$zeroStatusCount = self::find()->where('
user_id = :user_id AND sender_id != :user_id AND status = :status',
[
'user_id' => Yii::$app->user->id,
'status' => 0,
])
->groupBy('sender_id')
->count();
/**
...
* @property string $inn
* @property string $snils
*/
class User extends ActiveRecord
{
...
public function getInn()
{
return $this->profile->inn;
}
public function getSnils ()
{
return $this->profile->snils ;
}
...
}
class FooSearch extends Foo
{
public $destinationUser;
public function rules()
{
return [
...
['destinationUser', 'safe'],
...
];
}
public function search($params)
{
$query = Foo::find();
$query->joinWith(['destinationUser']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
// Для сортировки по User->username
$dataProvider->sort->attributes['destinationUser'] = [
'asc' => ['user.username' => SORT_ASC],
'desc' => ['user.username' => SORT_DESC],
];
...
$query->andFilterWhere([
...
])
// Для поиска по имени
->andFilterWhere(['like', 'user.username', $this->destinationUser]);
return $dataProvider;
}
[
'attribute' => 'destinationUser',
'options' => ['width'=>'200px'],
'value' => 'destinationUser.username',
]
...
class Module extends \yii\base\Module
{
...
public function init()
{
parent::init();
$this->layout = 'admin';
}
...
}
public function all($db = null)
{
$this->active();
return parent::all($db);
}
public function init()
{
parent::init();
$this->active();
}
...
// Asset bundle for compression output:
'targets' => [
'frontend' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot/',
'baseUrl' => '@web/',
'css' => 'css/all-front-{hash}.css',
'js' => 'js/all-front-{hash}.js',
'depends' => [
// Include all assets shared between 'backend' and 'frontend'
'app\assets\AppAsset',
'yii\web\YiiAsset',
'yii\web\JqueryAsset'
],
],
],
...
$form->field($model, 'login', ['enableAjaxValidation' => true]);
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
use app\assets\PostAsset;
PostAsset::register($this); // $this - представляет собой объект представления