Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
yii2:docs [2017/03/19 15:33] – [Behaviors/Filters] mirocowyii2:docs [2019/04/18 13:17] (текущий) – [Active Record] mirocow
Строка 375: Строка 375:
     public function getCreator()     public function getCreator()
     {     {
-        return $this->hasOne('User', array('id' => 'user_id'));+        return $this->hasOne('User', ['id' => 'user_id']);
     }     }
     public function getComments()     public function getComments()
     {     {
-        return $this->hasMany('Comment', array('post_id' => 'id'));+        return $this->hasMany('Comment', ['post_id' => 'id']);
     }     }
     public function getTrustComments($isTrust = true)     public function getTrustComments($isTrust = true)
     {     {
-        return $this->hasMany('Comment', array('post_id' => 'id')+        return $this->hasMany('Comment', ['post_id' => 'id']
-            ->where('status = :status', array(+            ->where('status = :status', [
                      ':status' => $isTrust ? self::TRUST : self::UNTRUST,                      ':status' => $isTrust ? self::TRUST : self::UNTRUST,
-              ))+              ])
             ->orderBy('id');             ->orderBy('id');
     }     }
Строка 416: Строка 416:
 // looking for a post  // looking for a post 
 $post = $query $post = $query
-   ->where(array('id' => 10, 'status' => Post::READ))+   ->where(['id' => 10, 'status' => Post::READ])
    ->one();    ->one();
    
 // or easier: "where" condition can be transmitted directly to the factory method // or easier: "where" condition can be transmitted directly to the factory method
-$post = Post::find(array('id' => 10, 'status' => Post::READ));+$post = Post::find(['id' => 10, 'status' => Post::READ]);
    
 // having transmitted to the factory method not a massive, but a number equivalent to the primary key search  // having transmitted to the factory method not a massive, but a number equivalent to the primary key search 
 $post = Post::find(10) $post = Post::find(10)
-   ->where(array('status' => Post::READ))+   ->where(['status' => Post::READ])
    ->one();    ->one();
    
Строка 432: Строка 432:
 // the result as an array // the result as an array
 $posts = $query->asArray()->all(); $posts = $query->asArray()->all();
 +</code>
 +
 +<code php>
 +User::find()->where(['and', ['phone_number' => $phone], ['<>', 'id', $user->id] ])->exists();
 +User::find()->where(['or', ['phone_number' => $phone], ['=', 'id', $user->id] ])->exists();
 </code> </code>
  
Строка 535: Строка 540:
     {     {
         return [         return [
-                  ['attribute1', 'attribute2', ...], +                  
-                  'validator class or alias', +                    ['attribute1', 'attribute2', ...], 
-                  // specifies in which scenario(s) this rule is active. +                    'validator class or alias', 
-                  // if not given, it means it is active in all scenarios +                    // specifies in which scenario(s) this rule is active. 
-                  'on' => ['scenario1', 'scenario2', ...], +                    // if not given, it means it is active in all scenarios 
-                  // the following name-value pairs will be used +                    'on' => ['scenario1', 'scenario2', ...], 
-                  // to initialize the validator properties +                    // the following name-value pairs will be used 
-                  'property1' => 'value1', +                    // to initialize the validator properties 
-                  'property2' => 'value2', +                    'property1' => 'value1', 
-                  // ...+                    'property2' => 'value2', 
 +                    // ... 
 +                  ], 
 +                  [ 
 +                    ['attribute1', 'attribute2', ...], 
 +                    'validator class or alias', 
 +                    // specifies in which scenario(s) this rule is active. 
 +                    // if not given, it means it is active in all scenarios 
 +                    'except' => ['scenario1', 'scenario2', ...], 
 +                    // the following name-value pairs will be used 
 +                    // to initialize the validator properties 
 +                    'property1' => 'value1', 
 +                    'property2' => 'value2', 
 +                    // ... 
 +                  ],          
               ];               ];
     }     }
Строка 1014: Строка 1033:
  }  }
 </code> </code>
 +
 +==== Params / Параметры ====
 +
 +<code php>
 +<?php
 +
 +namespace console\controllers;
 +
 +use yii\console\Controller;
 +
 +class QueueController extends Controller
 +{
 +    public $pid_file = '';
 +
 +    public function __get($name)
 +    {
 +        $name = str_replace('-', '_', $name);
 +
 +        return $this->$name;
 +    }
 +
 +    public function __set($name, $value)
 +    {
 +        $name = str_replace('-', '_', $name);
 +
 +        $this->$name = $value;
 +    }
 +
 +
 +    public function options($actionID)
 +    {
 +        return ['pid-file'];
 +    }
 +
 +    public function actionRun()
 +    {
 +
 +    }
 +}
 +</code>
 +
  
 ===== User ===== ===== User =====