{"id":157769,"date":"2012-11-07T19:22:03","date_gmt":"2012-11-07T15:22:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=157769"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=157769","title":{"rendered":"<span class=\"post_title\">\u0424\u0438\u0447\u0438, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b\u0435 \u0432 Yii, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0417\u0430 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Yii Framework \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430. \u0425\u043e\u0447\u0443 \u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0445\u0430\u0431\u0440\u0430\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c. \u0412\u0441\u0451 \u0447\u0442\u043e \u043d\u0438\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u2014 \u043f\u043b\u043e\u0434\u044b \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0438 \u0442\u0440\u0435\u0437\u0432\u043e\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/p>\n<p>  \u0422\u043e, \u043e \u0447\u0435\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c:  <\/p>\n<ul>\n<li>\u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438: \u0447\u0435\u0440\u0435\u0437 ajax-\u0437\u0430\u043f\u0440\u043e\u0441 (\u0431\u0435\u0437 layout) \u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 layout<\/li>\n<li>\u041a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0431\u0435\u0437 \u043a\u043e\u0434\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/li>\n<li>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/li>\n<li>\u041a\u0430\u043a \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0451 \u0432 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/li>\n<li>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 (\u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u043d\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0444\u0430\u0439\u043b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0423\u043f\u0440\u043e\u0449\u0430\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0439<\/li>\n<\/ul>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438: \u0447\u0435\u0440\u0435\u0437 ajax-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438 \u0441 layout<\/h4>\n<p>  <b>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/b> \u041e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0443\u043c\u0435\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 (\u043e\u0434\u043d\u0430 \u0438 \u0442\u0430\u0436\u0435 view + action) \u0438 \u043a\u0430\u043a \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0439 \u0447\u0435\u0440\u0435\u0437 ajax ( $.load() ) \u0438 \u043a\u0430\u043a \u0446\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 layout.<br \/>  <b>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/b> \u0422\u0430\u0431\u044b \u043d\u0430 bootstrap \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 ajax. \u041e\u043d\u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 &lt;li&gt;&lt;a&gt;&lt;\/a&gt;&lt;\/li&gt; \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u00ab\u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0432 \u043d\u043e\u0432\u043e\u043c \u043e\u043a\u043d\u0435\u00bb \u2014 \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u043e\u0442\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 layout.<br \/>  <b>\u041a\u043e\u0434:<\/b>  <\/p>\n<pre><code class=\"php\"># protected\/components\/LController.php class LController extends CController {     public function init() {         parent::init();         if (Yii::app()-&gt;request-&gt;getIsAjaxRequest()) {                    $this-&gt;layout = '\/\/layouts\/clear';        }     } } # themes\/classic\/views\/layouts\/clear.php: &lt;?= $content ?&gt; # \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445, \u0433\u0434\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043e\u0442 LController: class DefaultController extends LController { \u2026. }<\/code><\/pre>\n<h4>\u041a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0431\u0435\u0437 \u043a\u043e\u0434\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>  <b>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/b> \u0412\u0441\u0435 \u043c\u044b (\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u043e\u0434 Yii) \u0432 \u043a\u0430\u043a\u043e\u0439 \u0442\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c findByPk \u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438. \u041f\u0443\u0441\u0442\u044c \u043e\u043d\u0438 \u0438 \u043f\u043e Primary Key, \u043d\u043e \u0441\u0430\u043c \u0444\u0430\u043a\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u0435\u043d. \u0417\u0434\u0435\u0441\u044c \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0432 Yii \u0440\u0430\u0437 \u0438 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0441\u0443\u043d\u0443\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043a\u0435\u0448 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u0441\u0430\u043c\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445<br \/>  <b>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435:<\/b> \u041b\u044e\u0431\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 ActiveRecord \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434\u044b save() \u0438 delete() \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<br \/>  <b>\u041a\u043e\u0434:<\/b>  <\/p>\n<pre><code class=\"php\"># protected\/components\/LActiveRecord.php class LActiveRecord extends CActiveRecord {          public static function getByPk($pk){                 $cache = Yii::app()-&gt;cache-&gt;get(\u2018activerecord.\u2019.self::$clss.\u2019.\u2019.$pk);                 if ($cache) $cache = unserialize($cache);                 if ($cache) return $cache;                 $clss = self::$class                 $entity = $clss::model()-&gt;findByPk($pk);                 Yii::app()-&gt;cache-&gt;set(\u2018activerecord.\u2019.self::$clss.\u2019.\u2019.$pk,serialize($entity));         }                  public function save($runValidation = true, $attributes = NULL){                 $result = parent::save($runValidation, $attributes);                 $self = get_class($this);                 Yii::app()-&gt;cache-&gt;set(\u2018activerecord.\u2019.$self::$clss.\u2019.\u2019.$pk, serialize($this));                 return $result;         }                  public function delete() {                 $self = get_class($this);                 $ret = parent::delete();                 Yii::app()-&gt;cache-&gt;delete(\u2018activerecord.\u2019.$self::$clss.\u2019.\u2019.$pk);                 return $ret;         } } #\u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442 LActiveRecord: class User extends LActiveRecord {         public final static $clss = \u201cUser\u201d; \/\/\u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 (\u0431\u044b\u043b\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435-\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435)         ... }  #\u0432\u0441\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u043e Primary Key \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a: $user = User::getByPk(1); <\/code><\/pre>\n<h4>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438<\/h4>\n<p>  <b>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/b> \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u2014 \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430, \u0441 \u0447\u0435\u043c. \u041f\u043e\u043b\u0435\u0437\u043d\u043e \u0438 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0438 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<br \/>  <b>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435:<\/b> \u043f\u043e\u0447\u0442\u0438 \u0432\u0435\u0437\u0434\u0435 \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435<br \/>  <b>\u041a\u043e\u0434:<\/b><br \/>  \u0412 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043b\u0430\u0441\u0441 LActiveRecord \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<pre><code class=\"php\"># \u0432 \u043c\u0435\u0442\u043e\u0434 save (\u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u0440\u043e\u0433\u043e parent::save): $ts = microtime(true); if ($this-&gt;isNewRecord) {         $action = 'create\/' . $this-&gt;id; } else {         $action = 'update\/' . $this-&gt;id; } $result = parent::save($runValidation, $attributes); $ts = microtime(true)-$ts; $this-&gt;logMe($action.\u2019   time: \u2019.ts);  # \u0432 \u043c\u0435\u0442\u043e\u0434 delete (\u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u0440\u043e\u0433\u043e parent::delete): $ts = microtime(true); $ret = parent::delete(); $ts = microtime(true)-$ts; $this-&gt;logMe('delete\/' . $this-&gt;id.\u2019   time:\u2019.$ts);  #\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 logMe: private function logMe($action){         $model_log = Yii::app()-&gt;params['model_log_file'];         $table = $this-&gt;tableName();         $str = date('[Y-m-d H:i:s]') . ' [' . $table . '] ' . ' ' . $action . &quot;\\r\\n&quot;;         error_log($str, 3, $model_log); }  #\u0432 \u043d\u0430\u0448\u0438 params \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u043b\u043e\u0433\u0430: \u2018'model_log_file\u2019 =&gt; \u2018\/var\/www\/application\/logs\/model.log\u2019; <\/code><\/pre>\n<p>  \u0418 \u0441\u043d\u043e\u0432\u0430 \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u044b \u043e\u0442 LActiveRecord.<\/p>\n<h4>\u041a\u0430\u043a \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0451 \u0432 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/h4>\n<p>  <b>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/b> \u041c\u043d\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0431\u044b\u043b\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432\u0435\u0437\u0434\u0435, \u044f \u0432\u044b\u043d\u0435\u0441 \u0435\u0433\u043e \u0432 \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 yii \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<br \/>  <b>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435:<\/b> \u0432\u0435\u0437\u0434\u0435 \u0433\u0434\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u0430\u0448\u0443 \u0432 \u0431\u0430\u0437\u0435<br \/>  <b>\u041a\u043e\u0434:<\/b><br \/>  \u0412 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 LController \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434:  <\/p>\n<pre><code class=\"php\">public function run($actionID) {         \/\/\u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441 \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u044b \u0438\u0437 \u044f\u0434\u0440\u0430 yii:         if(($action=$this-&gt;createAction($actionID))!==null) {                 if(($parent=$this-&gt;getModule())===null)                         $parent=Yii::app();                 if($parent-&gt;beforeControllerAction($this,$action)) {                         \/\/\u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043e\u0442 \u043a\u043e\u0434\u0430 yii, \u0432 \u043d\u0435\u043c \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e:                         try {                                 $transaction=Yii::app()-&gt;db-&gt;beginTransaction();                                 $this-&gt;runActionWithFilters($action,$this-&gt;filters()); \/\/\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u044d\u043a\u0448\u0438\u043d                                 $transaction-&gt;commit(); \/\/\u0432\u0441\u0451 \u043e\u043a                         } catch (Exception $e){                                 $transaction-&gt;rollback(); \/\/\u0432\u0441\u0451 \u0443\u043f\u0430\u043b\u043e                                 throw $e;                         }                         \/\/\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c yii:                         $parent-&gt;afterControllerAction($this,$action);                 }         } else                 $this-&gt;missingAction($actionID); } #\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0441\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0433\u0434\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043d\u0430\u0434\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 LController <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 run \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 yii \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 CController. \u041d\u0430\u043c \u043f\u043e\u0432\u0435\u0437\u043b\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c. \u0418\u0437-\u0437\u0430 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u043a\u043e\u0434 Yii, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043b\u043e\u0445\u043e\u0433\u043e \u043d\u0435\u0442 \u2014 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d \u0438 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h4>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0430. \u0423\u043f\u0440\u043e\u0449\u0430\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0439<\/h4>\n<p>  <b>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/b> \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0434\u0435\u043f\u043b\u043e\u0439 \u043a\u043e\u0434\u0430 \u043d\u0430 N \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e git pull. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443 \u043d\u0430\u0441 \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433 (\u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e). \u042f\u0432\u043d\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0440\u0443\u043a\u0430\u043c\u0438 \u0432\u044b\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u0431\u0430\u0437\u044b, memcached, \u0434\u0440\u0443\u0433\u0438\u0445 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a.<br \/>  <b>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435:<\/b> \u0412\u0435\u0437\u0434\u0435 \u0433\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438, \u0445\u043e\u0442\u044c \u0443 2\u0445 \u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u043e\u0432 \u0438 \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0438\u043d\u0435.<br \/>  <b>\u041a\u043e\u0434:<\/b>  <\/p>\n<pre><code class=\"php\">#\/protected\/config\/main.php #\u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0430\u0439\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443: $local_config = require(dirname(__FILE__).\u2019\/local.php\u2019);  #\/protected\/config\/local.php: return array(         \u2018db\u2019 =&gt; array(                                                                     \/\/\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u044e\u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u043d\u0430\u0448\u0435\u0439 \u0411\u0414, 'connectionString', 'username', \u2018password\u2019         ),         \u2018memcache_servers\u2019 =&gt; array(                 array('host'=&gt;'127.0.0.1', 'port'=&gt;11211, 'weight'=&gt;60), \/\/\u0432\u0430\u0448\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 memcached         ) )  # \u0432 \/protected\/config\/main.php \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f: # 1. \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043b\u044e\u0447 \u2018db\u2019 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u0430\u043a\u0438\u043c: 'db'=&gt;$local_config[\u2018db\u2019];  # 2. \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043b\u044e\u0447 \u2018servers\u2019 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u2018cache\u2019 \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u0430\u043a\u0438\u043c: 'servers'=&gt;$local_config[\u2018memcache_servers\u2019] <\/code><\/pre>\n<p>  \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 .gitignore \u0444\u0430\u0439\u043b local.php. \u041f\u0435\u0440\u0435\u0434 \u0434\u0435\u043f\u043b\u043e\u0435\u043c \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<\/p>\n<p>  \u042d\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f?<br \/>  \u0414\u0430 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 <a href=\"http:\/\/note-space.com\">note-space.com<\/a> \u0443\u0436\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u043e\u0434\u0430. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u044d\u0442\u043e \u043d\u0430 Yii 1.1.8, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0442 \u2014 \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0412\u0430\u043c \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u043e\u0434 \u0412\u0430\u0448\u0443 \u0432\u0435\u0440\u0441\u0438\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<p>  <b>P.S<\/b>. \u0415\u0441\u043b\u0438 \u0412\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043f\u0440\u044f\u043c\u043e \u043a\u043e \u043c\u043d\u0435 \u2014 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0434 \u043f\u043e\u043c\u043e\u0447\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043b\u0443\u0447\u0448\u0435.    \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\/157769\/\"> http:\/\/habrahabr.ru\/post\/157769\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0417\u0430 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Yii Framework \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430. \u0425\u043e\u0447\u0443 \u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0445\u0430\u0431\u0440\u0430\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c. \u0412\u0441\u0451 \u0447\u0442\u043e \u043d\u0438\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u2014 \u043f\u043b\u043e\u0434\u044b \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0438 \u0442\u0440\u0435\u0437\u0432\u043e\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/p>\n<p>  \u0422\u043e, \u043e \u0447\u0435\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c:  <\/p>\n<ul>\n<li>\u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438: \u0447\u0435\u0440\u0435\u0437 ajax-\u0437\u0430\u043f\u0440\u043e\u0441 (\u0431\u0435\u0437 layout) \u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 layout<\/li>\n<li>\u041a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0431\u0435\u0437 \u043a\u043e\u0434\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/li>\n<li>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/li>\n<li>\u041a\u0430\u043a \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0451 \u0432 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/li>\n<li>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 (\u0441 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u043d\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0444\u0430\u0439\u043b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0423\u043f\u0440\u043e\u0449\u0430\u0435\u043c \u0434\u0435\u043f\u043b\u043e\u0439<\/li>\n<\/ul>\n<p>  <\/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-157769","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/157769","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=157769"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/157769\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=157769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=157769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=157769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}