Tag Archive for 'yii'

Yii CJSON

1
2
3
4
5
      $this->layout=false;
      header('Content-type: application/json');
      echo CJSON::encode(array('id'=>$project->id, 'content'=>$project->content, 'pass_way'=>$project->pass_way, 'total'=>$count, 'bs'=>$project->multiple
         ));
      Yii::app()->end();

How to get current controller name and action name in Yii

To get current controller name/id inside your controller, or view

1
2
3
$controllerId = Yii::app()->controller->id;
//or
$controllerId = $this->getId();

To get current action name/id being executed, if you are inside beforeAction() or afterAction(), use the received CAction argument

1
2
3
4
5
//inside beforeAction or afterAction
public function beforeAction($action)
{
  $actionId = $action->id;
...

or just elsewhere inside your controller

1
$actionId = $this->getAction()->getId();

YII 数据库连接(MySQL)

1
2
3
4
5
6
<?php
'class'=>'CDbConnection',
                'connectionString'=>'mysql:host=localhost;dbname=yiiblog;unix_socket=/opt/lampp/var/mysql/mysql.sock',
                'username'=>'root',
                'password'=>'password',
                'charset'=>'utf8',