['date_to', 'date', 'when' => function($model){
return strtotime($model->date_to) < strtotime($model->date_from);
}]
$query = In::find()
->joinWith(['couple' => function(ActiveQuery $query){
$query->from(['c1' => Couple::tableName()])
}])
->joinWith(['couple' => function(ActiveQuery $query){
$query->from(['c2' => Couple::tableName()])
}]);
$query
->andFilterWhere(['like', 'couple.nomer', $this->couple_nomer])
->andFilterWhere(['like', 'c1.dancerId1.sname', $this->dancerId1])
->andFilterWhere(['like', 'c2.dancerId2.sname', $this->dancerId2]);
->joinWith(['couple' => function(ActiveQuery $query){
замените "couple" на имя связи $user = User::findOne($userId);
$model = new UserEditForm();
class User extends ActiveRecord
{
// тут и правила проверки и соединение с таблицей и атрибуты и всё-всё.
}
public function actionCreate() {
$model = new UserEditForm();
if($model->load($user) && $model->save()){
// redirect при успешном сохранении модели
}
return $this->renderAjax('_form-edit', [
'model' => $model,
]);
}
public function actionUpdate($id) {
$userId = (int)Yii::$app->request->get('id');
$user = User::findOne($userId);
if($model->load($user) && $model->save()){
}
return $this->renderAjax('_form-edit', [
'model' => $model,
]);
}
$userId = (int)Yii::$app->request->get('id');
/*
*переделать в метод, который будет возвращать или модель
*или сообщение о том, что нужной записи в базе нет
*
*/
$model =User::findOne($userId);
if($model->load($model)){
// что-то делаете
}
return $this->renderAjax('_form-edit', [
'model' => $model,
]);
User::findOne();
. Возможно, что ответ от базы приходит пустой. $modelUserForm = $this->findModel($id);
return $this->renderAjax('_form-user', [
'modelUserForm' => $modelUserForm
]);
http://site.ru/user/update/1
, то есть - настроить UrlManager. Запрос будет идти на контролер user в действие update и с id выбранного пользователя.actionUpdateStatus($id)
. В действии проверять, пришёл ajax запрос или какой-то другой. После этой проверки обновлять в таблице поле "статус" у выбранного пользователя.2. Может есть более элегантный способ сменить статус юзеру по клику, который предлгалает сама yii?
public function getAssociatedArray()
{
return $this->getAssociatedProducts()->select('id')->column();
}
<?= $form->field($model, 'associatedArray')->dropDownList(Catalog::getChildCategoryList(),
[
'multiple' => true,
'class' => 'select-multiple',
'style' => 'width:100%;',
])
?>
Call to a member function isAttributeRequired() on array
// Action 1
$session = Yii::$app->session;
if($session->isActive){
$session->set('TEST', 123);
}
// Action 2
$session = Yii::$app->session;
echo $session->get('TEST');
public function safeUp()
{
$this->alterColumn('order','street', $this->string()->notNull->defaultValue(0));
}
public function safeDown()
{
$this->alterColumn('order','street', $this->string()); // будет значение по умолчанию null
}
if (!$this->validate()) {
return null;
}
public function signup()
{
if($this->validate()){
$user = new Users();
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if($user->save()){
// после успешного сохранения в базу отправляете письмо или ещё что-то делаете
}
return $user;
}
return null;
}