What difference does he have with these methods, such as Actionindex? What I saw in Yii's video tutorial was to do the verification code.
Reply content:
What difference does he have with these methods, such as Actionindex? What I saw in Yii's video tutorial was to do the verification code.
For example, define an action with a file, rather than define it in a controller
function actions(){ return array( 'edit'=>'application.controllers.post.UpdateAction', ); }
For example:
Official example: in the 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'), ), ); }
You can access the verification code directly through the Xxx?r=site/captcha!
Common operations, Acontroller and Bcontroller have an edit method that you can put into actions
Thanks for inviting! :)
As the name implies, there action
is no doubt is used to describe the controller's actions, generally, that is actionIndex
, the default action.
Example:
class PageController extends Controller{ public function actionIndex() { echo 'default action'; }}
The default action, output, is triggered when the user requests it default action
.
Of course you can also define specific action
, for example:
class PageController extends Controller{ public function actionIndex() { echo 'default action'; } public function actionSelf() { echo 'new action'; }}
At this point, the output is triggered when the user requests an self
action new action
.
Of course you'll find CAction
another class, which is the other way to use it action
:
class SelfAction extends CAction{ public function run() { echo 'new action'; }}class PageController extends Controller{ public function actions() { return array( 'self' => 'application.controllers.actions.SelfAction', ); }}
The proposed master before the formal development, the first to YII
have a general understanding, you can read this document: "Yii authoritative guide"
When you want to make a single page, such as "About Us", "Contact Us", can be written in the actions.
Used to re-use the action.