Home > Backend Development > PHP Tutorial > Yii action method techniques_PHP tutorial

Yii action method techniques_PHP tutorial

WBOY
Release: 2016-07-13 09:57:21
Original
725 people have browsed it

Yii Action Method Tips

Action is defined as a method named with the word action as the prefix. A more advanced way is to define an action class and have the controller instantiate it when it receives a request. This allows actions to be reused, improving reusability.

1. Define an action class. The basic format is as follows:

class UpdateAction extends CAction{
	public function run(){
		//...逻辑代码...
	}
}
Copy after login

2. Use the action class: In order to let the controller notice this action, we need to override the actions() method of the controller class in the following way:

class PostController extends CController{
	public function actions(){
		return array(
		//使用"应用程序文件夹/controllers/post/UpdateAction.php" 文件中的类来处理edit动作
			'edit'=>'application.controllers.post.UpdateAction',
		);
	}
}
Copy after login

As shown above, we used the path alias application.controllers.post.UpdateAction to specify the action class file as protected/controllers/post/UpdateAction.php

By writing class-based actions, we can organize the application into a module style.

Articles you may be interested in

  • Eight classic techniques for Linux operating system applications
  • Yii controller action parameter binding processing
  • Summary of operations related to adding, modifying, and deleting yii databases
  • Ten tips to speed up Win7 system optimization
  • Improve database performance and reveal SQL optimization techniques
  • Research on PHP open source source code Methods and techniques
  • Summary of query techniques in ThinkPHP
  • Summary of yii database query operations

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/983633.htmlTechArticleYii Action method technique An action is defined as a method named with the word action as the prefix. A more advanced way is to define an action class and let the controller will...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template