Showing posts with label beforeAction. Show all posts
Showing posts with label beforeAction. Show all posts

Tuesday, July 23, 2013

Execute php script before every php script

  1. Make a .htaccess file in document root.
  2. Write the following code:
  3. php_value auto_prepend_file before_action.php
    php_value auto_append_file after_action.php
  4. create a file before_action.php in document root
  5. create a file after_action.php in document root
  6. or you can use full file path such: /var/www/html/site.com/before_action.php

http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file

Tuesday, April 16, 2013

How do I call a method before every controller action yii using beforeAction

http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail

protected function beforeAction(CAction $action)
{
    return true;
}

If you create this in your main Controller under components then you can call by:
return parent::beforeAction($action);

"protected/controllers/MyController.php"
<?php
protected function beforeAction(CAction $action)
{
    if(parent::beforeAction($action)) {
        return true;
    }
    return false;
}
?>

"protected/components/Controller.php"
<?php
protected function beforeAction(CAction $action)
{  
    require_once "protected/Utility/General.php"
    /* Do some common work here if you need in common controller */
    return true;
}
?>