{"id":178917,"date":"2013-05-06T20:26:03","date_gmt":"2013-05-06T16:26:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=178917"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=178917","title":{"rendered":"<span class=\"post_title\">Yii2. \u0417\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3b1\/b9a\/d15\/3b1b9ad157d40ef76a9b60f9e24311a0.png\" align=\"right\"\/> <\/p>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p> \u041d\u0430 \u0434\u043d\u044f\u0445, \u0441\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u042f \u0438 \u0434\u0443\u043c\u0430\u044e \u0435\u0449\u0435 \u043d\u0435\u043c\u0430\u043b\u043e \u043b\u044e\u0434\u0435\u0439 \u0436\u0434\u0430\u043b\u0438. \u0410\u0432\u0442\u043e\u0440\u044b Yii Framework \u0432\u044b\u043a\u0430\u0442\u0438\u043b\u0438 \u043f\u0440\u0435\u0432\u044c\u044e-\u0432\u0435\u0440\u0441\u0438\u044e.<\/p>\n<p>  \u0421\u043f\u0443\u0441\u0442\u044f \u0434\u0435\u043d\u044c \u0437\u0434\u0435\u0441\u044c \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 Yii2, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u044e. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0435 \u0445\u0443\u0436\u0435.<a name=\"habracut\"><\/a><\/p>\n<h4>\u041d\u0430\u0447\u0430\u043b\u043e<\/h4>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e. \u0421\u043f\u0438\u0441\u043e\u043a \u0432 \u043a\u0440\u0430\u0442\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0435:<\/p>\n<p>   \u2014 \u041e\u0442\u0434\u0435\u043b\u0438\u043b\u0438 \u044f\u0434\u0440\u043e \u043e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0439. \u0412\u044b\u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0427\u0430\u0441\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u043f\u0435\u0440\u0435\u043a\u043e\u0447\u0443\u044e\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435, \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0435, \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u0427\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0440\u0430\u043d\u0430 \u0438\u0437-\u0437\u0430 \u043d\u0435\u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>   \u2014 \u0411\u0430\u0437\u043e\u0432\u044b\u0439 <b>CComponent<\/b> \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b\u0438 \u043d\u0430 <b>Object<\/b> \u0438 <b>Component<\/b>. \u041f\u0435\u0440\u0432\u044b\u0439 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u0432, \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044f \u043f\u0435\u0440\u0432\u044b\u0439, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p>\n<p>  -\u0412\u0438\u0434\u043e\u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0439. \u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0435<\/p>\n<pre><code class=\"php\">$post-&gt;on('update', function($event) {     \/\/ send email notification }); <\/code><\/pre>\n<p>  \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<pre><code class=\"php\">$component = \\Yii::createObject(array(   'class' =&gt; '\\app\\components\\GoogleMap',   'apiKey' =&gt; 'xyz',   \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435   'on eventName' =&gt; array('Event', 'run'),   \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435   'as behaviorName' =&gt; array(\/* Behavior config *\/), )); <\/code><\/pre>\n<p>   \u2014 \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <b>View<\/b>, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 MVC \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"php\">&lt;?php use yii\\helpers\\base\\Html; \/**  * \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 $this \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.  * \u0414\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443 \u043c\u043e\u0436\u043d\u043e $this-&gt;context  * @var yii\\base\\View $this  *\/ $this-&gt;title = 'Hello world'; ?&gt; &lt;h1&gt;&lt;?php echo Html::encode($this-&gt;title); ?&gt;&lt;\/h1&gt; &lt;p class=&quot;lead&quot;&gt;\u041f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440!&lt;\/p&gt; <\/code><\/pre>\n<p>* View \u043c\u043e\u0436\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c, \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>   \u2014 \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442. \u041e\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre><code class=\"php\">public function actionIndex() { \techo $this-&gt;render('index'); } <\/code><\/pre>\n<p>   \u2014 \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0434\u0432\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u0430 \u043a\u043e\u0442\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f: <b>beforeAction<\/b>, <b>afterAction<\/b><\/p>\n<pre><code class=\"php\">public function init() {   $this-&gt;on('beforeAction', function($event) {     \/\/ \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435     $event-&gt;isValid = false;   }); } <\/code><\/pre>\n<p>   \u2014 \u0423\u0431\u0440\u0430\u043d\u044b \u0444\u0438\u043b\u044c\u0442\u0440\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <b>CFilter<\/b>, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"php\">public function behaviors() {   return array(     'AccessControl' =&gt; array(       'class' =&gt; '\\yii\\web\\AccessControl',       'rules' =&gt;array(\/* \u0442\u0443\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u043e\u0441\u044c *\/),     ),   ); } <\/code><\/pre>\n<p>   \u2014 \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u2014 \u043c\u0435\u0442\u043e\u0434 <b>populate<\/b><\/p>\n<pre><code class=\"php\">public function actionLogin() {   $model = new LoginForm();   if ($this-&gt;populate($_POST, $model) && $model-&gt;login()) {     Yii::$app-&gt;response-&gt;redirect(array('site\/index'));   }    echo $this-&gt;render('login', array(     'model' =&gt; $model,   )); } <\/code><\/pre>\n<p>   \u2014 \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u0445\u0435\u043b\u043f\u0435\u0440\u043e\u0432: <b>ArrayHelper<\/b>, <b>StringHelper<\/b>, <b>SecurityHelper<\/b>. \u0412\u0441\u0435 \u0445\u0435\u043b\u043f\u0435\u0440\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u044c \u0447\u0435\u0440\u0435\u0437 LSB. \u0423\u0440\u0430, \u0432\u043e\u0441\u043a\u043b\u0438\u043a\u043d\u0443\u043b \u044f, \u0442.\u043a \u043b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u043d\u0435 \u0440\u0430\u0437 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u044c <b>Html<\/b>.<\/p>\n<p>   \u2014 \u0412\u0438\u0434\u0436\u0435\u0442 <b>ActiveForm<\/b> \u0442\u043e\u0436\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d, \u0438 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442 \u0444\u043e\u0440\u043c-\u0431\u0438\u043b\u0434\u0435\u0440 <b>CForm<\/b>. \u041a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0444\u043e\u0440\u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 <b>ActiveField<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 <b>ActiveForm<\/b><\/p>\n<pre><code class=\"php\">$form = $this-&gt;beginWidget('yii\\widgets\\ActiveForm', array(   'options' =&gt; array('class' =&gt; 'form-horizontal') ));    echo $form-&gt;field($model, 'username')-&gt;textInput();    echo $form-&gt;field($model, 'password')-&gt;passwordInput();    echo $form-&gt;field($model, 'rememberMe')-&gt;checkbox();    echo Html::tag('div', Html::submitButton('Login', null, null, array('class' =&gt; 'btn btn-primary')), array(     'class' =&gt; 'form-actions'    ));  $this-&gt;endWidget(); <\/code><\/pre>\n<p>* <b>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0432 Html::tag($tag, $content, $options) \u2014 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432!<\/b><\/p>\n<h4>ActiveRecord<\/h4>\n<blockquote><p>\u00ab\u041f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438, ActiveRecord \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043d\u0435\u0442\u0440\u043e\u043d\u0443\u0442\u043e\u0439\u00bb<\/p><\/blockquote>\n<p> \u2014 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u0412\u0435\u0440\u043d\u043e \u043f\u043e\u0434\u043c\u0435\u0447\u0435\u043d\u043e \u2014 \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u043b\u0438. <br \/>  \u041f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u043b\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 ActiveRecord. <\/p>\n<p>   \u2014 \u0417\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e <b>model()<\/b><\/p>\n<p>   \u2014 \u0423\u0431\u0440\u0430\u043d <b>CDbCriteria<\/b>. \u041d\u043e \u043d\u0435 \u043f\u0443\u0433\u0430\u0439\u0442\u0435\u0441\u044c, \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0441\u0442\u0430\u043b\u0430 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043b\u0435\u0433\u0447\u0435. \u041f\u043e\u044f\u0432\u0438\u043b\u0441\u044f <b>ActiveQuery<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0435\u0431\u044f \u0433\u0438\u0431\u0440\u0438\u0434 <b>CActiveFinder<\/b> \u0438 <b>CDbCriteria<\/b>.<\/p>\n<pre><code class=\"php\">\/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 ActiveQuery $query = Post::find();  \/\/ \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u044b $posts = $query-&gt;all();  \/\/ \u0438\u0449\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u044b \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c $posts = $query     -&gt;where(array('status' =&gt; Post::DRAFT))     -&gt;orderBy('time')     -&gt;all();  \/\/ \u0438\u0449\u0435\u043c \u043e\u0434\u0438\u043d \u043f\u043e\u0441\u0442  $post = $query    -&gt;where(array('id' =&gt; 10, 'status' =&gt; Post::READ))    -&gt;one();  \/\/ \u0438\u043b\u0438 \u043f\u0440\u043e\u0449\u0435, \u0443\u0441\u043b\u043e\u0432\u0438\u0435 where \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 $post = Post::find(array('id' =&gt; 10, 'status' =&gt; Post::READ));  \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0430 \u0447\u0438\u0441\u043b\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043f\u043e\u0438\u0441\u043a\u0443 \u043f\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443  $post = Post::find(10)    -&gt;where(array('status' =&gt; Post::READ))    -&gt;one();  \/\/ \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 $posts = $query-&gt;indexBy('title')-&gt;all();  \/\/ \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 $posts = $query-&gt;asArray()-&gt;all(); <\/code><\/pre>\n<p>   \u2014 \u0412\u0441\u0435 \u043e\u0431\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435: <b>getDb<\/b>, <b>tableName<\/b>, <b>find<\/b>*, <b>save<\/b>*, <b>primaryKey<\/b>. \u0412\u044b\u0438\u0433\u0440\u044b\u0448 \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d.<\/p>\n<p>   \u2014 \u0421\u0432\u044f\u0437\u0438, \u043a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u043d\u0438\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0432\u044f\u0437\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432<\/p>\n<pre><code class=\"php\">class Post extends ActiveRecord {     public function getCreator()     {         return $this-&gt;hasOne('User', array('id' =&gt; 'user_id'));     }     public function getComments()     {         return $this-&gt;hasMany('Comment', array('post_id' =&gt; 'id'));     }     public function getTrustComments($isTrust = true)     {         return $this-&gt;hasMany('Comment', array('post_id' =&gt; 'id'))             -&gt;where('status = :status', array(                      ':status' =&gt; $isTrust ? self::TRUST : self::UNTRUST,               ))             -&gt;orderBy('id');     } } <\/code><\/pre>\n<p>   \u2014 \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0432\u044f\u0437\u044f\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 <b>link<\/b>() \u0438 <b>unlunk<\/b>(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u044f\u0442 \u043a\u043b\u044e\u0447\u0438<\/p>\n<pre><code class=\"php\">$post = Post::find(1);  $comment = new Comment(); $comment-&gt;text = 'Yii Framework is cool!'; $post-&gt;link('comments', $comment); <\/code><\/pre>\n<p>   \u2014 \u0418\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0433\u0440\u0443\u043f\u043f\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0435\u0441\u0442\u044c, \u043d\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0432\u0438\u0434\u0435. \u0423 \u043d\u0430\u0441 \u0436\u0435 \u043d\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 <b>CDbCriteria<\/b>, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0442\u043e\u0436\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442. \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u043f\u0440\u0438\u0447\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432 <b>Query<\/b><\/p>\n<pre><code class=\"php\">class Post extends \\yii\\db\\ActiveRecord {     \/**      * @param ActiveQuery $query      *\/     public static function byCreator($query, $userId)     {         $query-&gt;andWhere('user_id = :userId', array('userId' =&gt; $userId));     }     \/**      * @param ActiveQuery $query      *\/     public static function removed($query)     {         $query-&gt;andWhere('removed = 1');     } }  $posts = Post::find()-&gt;removed()-&gt;all(); $myPosts = Post::find()-&gt;byCreator(Yii::$app-&gt;user-&gt;id)-&gt;all(); <\/code><\/pre>\n<h4>\u0412\u0441\u0435<\/h4>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0442\u043e\u0447\u043a\u0443. \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f, \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043d\u043e \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u0432\u044b \u0432\u044b\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0438 \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438.<\/p>\n<p>  <i>\u0414\u043e \u0441\u0432\u044f\u0437\u0438.<\/i>    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/178917\/\"> http:\/\/habrahabr.ru\/post\/178917\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3b1\/b9a\/d15\/3b1b9ad157d40ef76a9b60f9e24311a0.png\" align=\"right\"\/> <\/p>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p> \u041d\u0430 \u0434\u043d\u044f\u0445, \u0441\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u042f \u0438 \u0434\u0443\u043c\u0430\u044e \u0435\u0449\u0435 \u043d\u0435\u043c\u0430\u043b\u043e \u043b\u044e\u0434\u0435\u0439 \u0436\u0434\u0430\u043b\u0438. \u0410\u0432\u0442\u043e\u0440\u044b Yii Framework \u0432\u044b\u043a\u0430\u0442\u0438\u043b\u0438 \u043f\u0440\u0435\u0432\u044c\u044e-\u0432\u0435\u0440\u0441\u0438\u044e.<\/p>\n<p>  \u0421\u043f\u0443\u0441\u0442\u044f \u0434\u0435\u043d\u044c \u0437\u0434\u0435\u0441\u044c \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 Yii2, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u044e. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043d\u0435 \u0445\u0443\u0436\u0435.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-178917","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/178917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=178917"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/178917\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=178917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=178917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=178917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}