Yii Tips and Tricks

While working on Project base on Yii framework, got some questions/problems. After searching couple of hours found solutions,So sharing here….,

  • How can change default action of Yii controller?

Ans:- Declare variable  ‘ public $defaultAction = ‘actioname’; ” in controller.
e.g.:-  class LoginController extends Controller
{             public $defaultAction = ‘login’;

  • How to change the default Controller of site in Yii?

Ans:- add ” ‘defaultController’=>’module/controller/action ”  in main.config

  • How to change the default theme of site?

    Ans:- add ” ‘theme’=>’theme-name ”  in main.config

  • How do I create a linked image or CHtml:link with an image?

    Ans:-
    $imghtml=CHtml::image(Yii::app()->theme->baseUrl.’/images/settings-icon.png’);
    echo CHtml::link($imghtml,Yii::app()->createAbsoluteUrl(‘/controller/action/’),array(“class”=>”classname”));

  • How to change the layout in contrlller?

    call  $this->layout = “//layouts/name” if you want change on particular action, or declare variable as,
    public $layout = “//layouts/name”;

  • How to set the time zone in Yii?

 We can set the time zone index.php using php function ,       date_default_timezone_set(‘Asia/Calcutta’);
But I found another way,
Open main.php & write as key =>pair value like,

return array(
‘timeZone’ => ‘Asia/Calcutta’,
……………….
……..
);

Advertisements

PHP Developer..

Tagged with:
Posted in PHP, Yii

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: