What is the difference between him and such methods as actionIndex? What I saw in the Yii video tutorial is the difference between the verification code and the actionIndex method? What I saw in the Yii video tutorial is the verification code.
Reply content:
What is the difference between him and such methods as actionIndex? What I saw in the Yii video tutorial is the verification code.
For example, define an action through a file instead of defining it in the controller.
function actions(){ return array( 'edit'=>'application.controllers.post.UpdateAction', ); }
For example:
Official example: In SiteController
public function actions() { return array( // captcha action renders the CAPTCHA image displayed on the contact page 'captcha'=>array( 'class'=>'CCaptchaAction', 'backColor'=>0xFFFFFF, ), // page action renders "static" pages stored under 'protected/views/site/pages' // They can be accessed via: index.php?r=site/page&view=FileName 'page'=>array( 'class'=>'CViewAction', ), 'search'=>array( 'class'=>'ext.esearch.SearchAction', 'model'=>'Post', 'attributes'=>array('title', 'tags', 'content'), ), ); }
Directly through xxx? R = site/captcha has accessed the verification code!
For public operations, both AController and BController have an edit method, which can be placed in actions.
Thank you! :)
As the name suggests,action
It is undoubtedly used to describe the action of the controller. GenerallyactionIndex
, That is, the default action.
Example:
class PageController extends Controller{ public function actionIndex() { echo 'default action'; }}
When a user requests, the default action is triggered and the output isdefault action
.
Of course, you can also define specificaction
For example:
class PageController extends Controller{ public function actionIndex() { echo 'default action'; } public function actionSelf() { echo 'new action'; }}
In this case, when the user requestsself
The output is triggerednew action
.
Of course, you will find thatCAction
Class, which is usedaction
Another method:
class SelfAction extends CAction{ public function run() { echo 'new action'; }}class PageController extends Controller{ public function actions() { return array( 'self' => 'application.controllers.actions.SelfAction', ); }}
We recommend that you firstYII
For a general understanding, read this document: Yii authoritative guide
When you create a single page, such as "About Us" and "Contact Us", you can write them all in actions.
Used to reuse actions