Yii 1 1 過濾器原理學習

2021-07-10 03:17:33 字數 1046 閱讀 2826

yii 1.1 的過濾器是在執行 action 前對某些操作。通過自定義過濾器,開發者可以在為一批 action 新增自己的驗證邏輯。可以粗略認為是在執行 action 前執行了乙個函式。

yii 1.1 過濾器的呼叫是在 controller 類的 run() 函式中,通過呼叫 runactionwithfilters() 函式,來逐一驗證 filters() 函式中定義的 filter。即在 controller 例項生成後,執行 action 前。

具體使用方法:

首先在 controller 中重寫 filters() 方法,該方法返回乙個過濾器配置陣列,每個資料元素代表乙個過濾器。對於不同的過濾器型別,陣列元素的格式也不同,後邊會詳細給出例子,所以先不贅述了。

在說過濾器的具體使用之前,首先需要了解乙個重要的類 cfilterchain 。此類用乙個 list 儲存了乙個指定 action 的所有 filter 。執行此類的 run() 方法會從 list 中取出乙個 filter 進行驗證,當 list 中沒有元素的時候,表示所有過濾器已順利通過,則會執行 action 。

所有過濾器類需繼承自 cfilter,通過重寫 prefilter() 和 postfilter 方法來實現自己的驗證邏輯。filter 方法需要傳入引數 filterchain ,該引數是乙個 cfilterchain 例項,如果該過濾器已驗證通過,則需要呼叫 $filterchain->run() ,之後框架會根據 list 中的過濾器來進行下邊的操作。

過濾器型別:

class

mycontroller

extends

ccontroller

public

function

filterinlinefiltername

($filterchain)

}

class

mycontroller

extends

ccontroller

}

vue學習 過濾器

作用 過濾資料,一般是把伺服器返回的資料,過濾成符合頁面展示的資料 1.私有過濾器 vue.component login data function filters 2.共有過濾器 最好把vue.filter放在元件註冊之前 vue.filter toup function input,name ...

YII中的過濾器的細節

to change this license header,choose license headers in project properties.to change this template file,choose tools templates and open the template i...

1 1 shiro 過濾器詳解

anon 例子 admins anon 沒有引數,表示可以匿名使用。authc 例如 admins user authc表示需要認證 登入 才能使用,沒有引數 roles 例子 admins user roles admin 引數可以寫多個,多個時必須加上引號,並且引數之間用逗號分割,當有多個引數時...