// 'dsn' => 'mysql:host="бла бла.ком";dbname=tor',
// 'username' => 'tor',
// 'password' => '',
// 'charset' => 'utf8',
'dsn' => 'mysql:host=127.0.0.1;dbname=tor',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'response' => [
'class' => 'yii\web\Response',
'format' => 'json',
'on beforeSend' => function ($event) {
$response = $event->sender;
if ($response->data !== null) {
$data = $response->data;
// Error handle
$error = '';
if( ! $response->isSuccessful) {
if(isset($data['message'])) {
$error = $data['message'];
} elseif(isset(current($data)['message'])) {
$error = current($data)['message'];
}
}
$response->data = [
'status' => $response->isSuccessful,
'code' => $response->statusCode,
'error' => $error,
];
if($response->isSuccessful) {
$response->data['data'] = $data;
}
// $response->statusCode = 200;
}
},
],
<?php
namespace app\common\components\widget\search;
use \Yii;
use \yii\base\Widget;
class Search extends Widget
{
public $placeholder;
public function __construct()
{
$this->placeholder = \Yii::t('company', 'Поиск...');
}
public function init()
{
}
public function run()
{
}
}
'components'=>array(
'oradb'=>array(
'class' => 'ext.oci8Pdo.OciDbConnection',
'connectionString' => 'oci:dbname=xxx.xxx.xxx.xxx:xxxx/dbo;charset=AMERICAN_AMERICA.cl8mswin1251',
'username' => 'login',
'password' => 'password',
'enableProfiling' => TRUE,
'enableParamLogging' => TRUE,
),
'mydb'=>array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=somedb',
'username' => 'login',
'password' => 'password',
'charset' => 'UTF8',
),
…
);
class Model extends CActiveRecord {
public function getDbConnection(){
return Yii::app()->db2; // db2 - имя базы из конфига
}
}