This article illustrates the use of filter filters in the Yii controller. Share to everyone for your reference, specific as follows:
Specify the filtering action (the following Projectcontext () method is used in new, list, manage page calls)
Public function Filters ()
{return
array (
' AccessControl ',//Perform access control for CRUD operations
' postonly + delete ',//We only allow deletion via POST request
' projectcontext +create index admin '
;
}
Add some filter logic, define filter method, filter method must add filter before
Public Function Filterprojectcontext ($filterChain)
{
$prijectId = null;
if (Isset ($_post[' pid ')) {
$projectId = $_post[' pid '];
ElseIf (Isset ($_get[' pid ')) {
$projectId = $_get[' pid '];
$this->loadproject ($projectId);
$filterChain->run ();
}
Public Function Loadproject ($projectid)
{
if ($this->_project = = null) {
$this->_project = Project::model ()->findbypk ($projectid);
if ($this->_project = = null) {
throw new chttpexception (404, ' request and item not found!) ');
}
}
return $this->_project;
}
For more information on YII-related content, readers who are interested in this site can view the topics: Introduction to YII Framework and summary of common skills, "Summary of PHP Excellent development framework", "Smarty Template Introductory Course", "Introduction to PHP object-oriented programming", "PHP string" Summary of Usage , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the YII framework.