yii workflow
Widget
Widget is an instance of the CWidget
1.
<?php $this->beginWidget('path.to.WidgetClass'); ?>
...body content that may be captured by the widget...
<?php $this->endWidget(); ?>
or
2.
<?php $this->widget('path.to.WidgetClass'); ?>
2 is used when you dont need any content in the widget body.
Application
The application object is instantiated as a singleton by the entry script. The application singleton can be accessed at any place via Yii::app().
By default, the application object is an instance of CWebApplication.
An alternative way of customizing it is to extend CWebApplication.
The configuration is an array of key-value pairs
We usually store the configuration in a separate PHP script (e.g. protected/config/main.php).
To apply the configuration, we pass the configuration file name as a parameter to the application's constructor, or to Yii::createWebApplication() in the following manner, usually in the entry script: $app=Yii::createWebApplication($configFile);
Core Application Components
Yii predefines a set of core application components to provide features common among Web applications.
By configuring the properties of these core components, we can change the default behavior of nearly every aspect of Yii.
Here is a list the core components that are pre-declared by CWebApplication:
Application Life Cycle
When handling a user request, an application will undergo the following life cycle:
Controller
A controller is an instance of CController or of a class that extends CController.
An action, in its simplest form, is just a controller class method whose name starts with action.
A controller has a default action. When the user request does not specify which action to execute, the default action will be executed. By default, the default action is named as index. It can be changed.
The siteController has
actionIndex(){
$this->render('index');
//where index is an index.php file in views/site
}
and actionContact(){
......
}
and many other actions.
by default yii urls follow http://localhost/yourapp/index.php?r=controller/action
THE END
More coming up in a few days..subscribe or follow
Note: this article is adapted from the Yii Framework Guide
- A user makes a request with the URL http://www.example.com/index.php?r=post/show&id=1
- The bootstrap script creates an application instance and runs it.
- The application obtains the detailed user request information from an application component named request.
- The application determines the requested controller and action with the help of an application component named urlManager.
- The application creates an instance of the requested controller to further handle theuser request.
- The action reads a Post model whose ID is 1 from the database.
- The action renders a view named show with the Post model.
- The view reads and displays the attributes of the Post model.
- The view executes some widgets
- The view rendering result is embedded in a layout
Widget
Widget is an instance of the CWidget
1.
<?php $this->beginWidget('path.to.WidgetClass'); ?>
...body content that may be captured by the widget...
<?php $this->endWidget(); ?>
or
2.
<?php $this->widget('path.to.WidgetClass'); ?>
2 is used when you dont need any content in the widget body.
Application
The application object is instantiated as a singleton by the entry script. The application singleton can be accessed at any place via Yii::app().
By default, the application object is an instance of CWebApplication.
An alternative way of customizing it is to extend CWebApplication.
The configuration is an array of key-value pairs
We usually store the configuration in a separate PHP script (e.g. protected/config/main.php).
To apply the configuration, we pass the configuration file name as a parameter to the application's constructor, or to Yii::createWebApplication() in the following manner, usually in the entry script: $app=Yii::createWebApplication($configFile);
Core Application Components
Yii predefines a set of core application components to provide features common among Web applications.
By configuring the properties of these core components, we can change the default behavior of nearly every aspect of Yii.
Here is a list the core components that are pre-declared by CWebApplication:
- assetManager: CAssetManager - manages the publishing of private asset files.
- authManager: CAuthManager - manages role-based access control (RBAC).
- cache: CCache - provides data caching functionality. Note, you must specify the actual class (e.g. CMemCache, CDbCache). Otherwise, null will be returned when you access this component.
- clientScript: CClientScript - manages client scripts (javascript and CSS).
- coreMessages: CPhpMessageSource - provides translated core messages used by the Yii framework.
- db: CDbConnection - provides the database connection. Note, you must configure its connectionString property in order to use this component.
- errorHandler: CErrorHandler - handles uncaught PHP errors and exceptions.
- format: CFormatter - formats data values for display purpose.
- messages: CPhpMessageSource - provides translated messages used by the Yii application.
- request: CHttpRequest - provides information related to user requests.
- securityManager: CSecurityManager - provides security-related services, such as hashing and encryption.
- session: CHttpSession - provides session-related functionality.
- statePersister: CStatePersister - provides the mechanism for persisting global state.
- urlManager: CUrlManager - provides URL parsing and creation functionality.
- user: CWebUser - carries identity-related information about the current user.
- themeManager: CThemeManager - manages themes.
Application Life Cycle
When handling a user request, an application will undergo the following life cycle:
- Pre-initialize the application with CApplication::preinit();
- Set up the class autoloader and error handling;
- Register core application components;
- Load application configuration;
- Initialize the application with CApplication::init()
- Register application behaviors;
- Load static application components;
- Raise an onBeginRequest event;
- Process the user request:
- Collect information about the request;
- Create a controller;
- Run the controller;
- Raise an onEndRequest event;
Controller
A controller is an instance of CController or of a class that extends CController.
An action, in its simplest form, is just a controller class method whose name starts with action.
A controller has a default action. When the user request does not specify which action to execute, the default action will be executed. By default, the default action is named as index. It can be changed.
The siteController has
actionIndex(){
$this->render('index');
//where index is an index.php file in views/site
}
and actionContact(){
......
}
and many other actions.
by default yii urls follow http://localhost/yourapp/index.php?r=controller/action
THE END
More coming up in a few days..subscribe or follow
Note: this article is adapted from the Yii Framework Guide
Comments
Post a Comment