CATEGORY: Yii

yii with pecl solr extension

Pecl solr requires libxml and libcurl in order to connect with solr server. Install the basis dependencies by

Once you have basic dependencies installed. Install pecl solr by

Yii-Filters

Filter

  • Executes before and/or after a controller action executes.It can also prevent further execution of action
  • E.g. access control filter – to ensure user authentication before executing the requested action.
  • An action can have multiple filters.
  • Order Of Execution : the order they defined in the filter list.
  • A filter can prevent the execution of the action and the rest of the un-executed filters.

Controller

Controller --- CController

  • An instance of CController or of a class that extends CController.
  • It is created by the application object when the user requests it.
  • An action is just a controller class method whose name starts with action.
  • actionIndex() is the defaultaction, when the user request doesn’t specify any action it will be executed
  • The defaultaction can be changed by setting the public instance variable, Ccontroller::defaultAction.
  • Controllers and actions are identified by IDs.
  • For e.g. the route “http://localhost/testApp/index.php?r=site/login” will call actionLogin of siteController
  • By default, the route are case-sensitive. By setting CUrlManager::caseSensitive to false in the application configuration, we can make the routes case-insensitive .

Yii Application Life Cycle

When handling a user request, an application will undergo the following life cycle:

1. Pre-initialize the application with Capplication::preinit();
2. Load application configuration
3. Set up class autoloader and error handling
4. Register core application components;
5. Initialize the application with CApplication::init()

MVC Components in detail

Bootstrap PHP script or Entry script

  • It handles user requests initially.
  • It is the only PHP script that end users can directly request to execute.
  • It contains the following code:

1. // remove the following line when in production mode
2. defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);
3. // include Yii bootstrap file
4. require_once(‘path/to/yii/framework/yii.php’);
5. // create application instance and run
6. $configFile=’path/protected/config/main.php’;
7. Yii::createWebApplication($configFile)->run();

Yii-MVC

Yii – An MVC Framework

model => information (the data) and the business rules
view => elements of the user interface such as text, form inputs;
controller => manages the communication between the model and the view.
A front-controller named application => access all the incoming request  and dispatches it to the appropriate controllers for further processing.

Gii- Model generator

Model generator

  • It generate Model for you.
  • For instance, You want to create a model for the table cnd
    • In the Table Name field, enter cnd.
    • In the Model Class field, enter Cnd. (Auto Filled)
    • Press the Preview button.
      • This will show us the new code file to be generated.
    • Now press the Generate button.
      • A new file named Cnd.phpwill be generated under protected/models.
  • Through this Cnd model class, you can access the underlying cnd table in an object-oriented fashion.