{"id":155127,"date":"2012-10-17T17:45:04","date_gmt":"2012-10-17T13:45:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=155127"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=155127","title":{"rendered":"<span class=\"post_title\">\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u043e\u0440\u043c \u0432 Yii<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442 \u0445\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440\u044b!<\/p>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 Yii \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0432\u0438\u0434\u0435\u043b, \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0431\u044b\u043b\u0430 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0441\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u0433\u0434\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0444\u043e\u0440\u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 \u0432\u0438\u0434\u0430 \u0447\u0435\u0440\u0435\u0437 \u0432\u0438\u0434\u0436\u0435\u0442 ActiveForm. \u0414\u0430, \u044d\u0442\u043e \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u0448\u0430\u0431\u043b\u043e\u043d. \u041d\u043e \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0444\u043e\u0440\u043c \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u044b.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0443 \u043d\u0430\u0441 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u00ab\u043d\u0435 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0444\u043e\u0440\u043c\u044b \u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u00bb. \u0410 \u0438\u0434\u0435\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u044b \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0444\u043e\u0440\u043c. <\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0448\u0438 \u0444\u043e\u0440\u043c\u044b. \u0422.\u0435. \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e \u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u0444\u043e\u0440\u043c\u044b \u0441\u0430\u043c\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0430 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<pre><code class=\"php\">\/**  * FormModel.  *  * @author     Andrey Nilov &lt;nilov@glavweb.ru&gt;  * @copyright  Copyright (c) 2007-2012 Glavweb.Soft, Russia. (http:\/\/glavweb.ru)  *\/ class FormModel extends CFormModel {     \/**      * Config of the form      * @var array      *\/     protected $_formConfig = array();      \/**      * Config of the form by default      * @var array      *\/     private $_defaultFormConfig = array(         'method' =&gt; 'post'     );             \/**      * Class name of form      * @var string      *\/     protected $_formClass = 'CForm';      \/**      * Object of Form      * @var Form      *\/     private $_form = null;                   \/**      * Constructor      *       * @param string $scenario Name of the scenario that this model is used in      * @return void      *\/     public function __construct($scenario = '')      {         parent::__construct($scenario);         $this-&gt;_setFormConfig();     }      \/**      * Sets config of the form      *       * @return void      *\/     private function _setFormConfig()      {         $this-&gt;_formConfig = array_replace_recursive(             $this-&gt;_defaultFormConfig,              $this-&gt;_formConfig()         );     }      \/**      * Returns config of the form      *       * @return array      *\/     protected function _formConfig()      {         return $this-&gt;_formConfig;     }          \/**      * Returns the attribute labels      *      * @return array Attribute labels (name=&gt;label)      *\/     public function attributeLabels()     {         return $this-&gt;getLabels();     }              \/**      * Returns the config of the form      *       * @return array      *\/     public function getFromConfig()      {         return $this-&gt;_formConfig;     }          \/**      * Sets the config of the form      *       * @param array $config      * @return void      *\/     public function setFromConfig(array $config)      {         $this-&gt;_formConfig = $config;     }          \/**      * Returns labels      *       * @return array      *\/     public function getLabels()      {         $labels = array();         if (!empty($this-&gt;_formConfig['elements'])) {             foreach ($this-&gt;_formConfig['elements'] as $name =&gt; $data) {                 if (isset($data['label'])) {                     $labels[$name] = $data['label'];                 }             }         }                  return $labels;     }          \/**      * Returns object of Form      *       * @return Form      *\/     public function getForm()      {         if ($this-&gt;_form === null) {             $this-&gt;_form = new $this-&gt;_formClass($this-&gt;_formConfig, $this);         }                  return $this-&gt;_form;     }     } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0443 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e. \u041c\u0430\u0441\u0441\u0438\u0432 &quot;$_formConfig&quot; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0444\u043e\u0440\u043c\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"php\">\/**  * Config of the form  * @var array  *\/ protected $_formConfig = array(     'activeForm' =&gt; array(         'class'                  =&gt; 'CActiveForm',         'id'                     =&gt; 'registration_form',         'enableClientValidation' =&gt; true,         'clientOptions' =&gt; array(             'validateOnSubmit' =&gt; true         )     ),      'elements' =&gt; array(         ....         'name' =&gt; array(             'type' =&gt; 'text',             'label' =&gt; '\u0424\u0418\u041e'         ),         'organization' =&gt; array(             'type' =&gt; 'text',             'label' =&gt; '\u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f'         ),        ....     ),      'buttons' =&gt; array(         'register' =&gt; array(             'type'  =&gt; 'submit',             'label' =&gt; '\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f'         )     ) ); <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 &quot;_formConfig()&quot;. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e &quot;$_formClass&quot; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b (CForm \u0438\u043b\u0438 \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043e\u043a).<\/p>\n<p>  \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0444\u043e\u0440\u043c\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u00abattributeLabels()\u00bb \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0440\u0430\u0432\u043d\u044b \u043b\u0435\u0439\u0431\u043b\u0430\u043c \u0438\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u043e\u0440\u043c\u044b (CForm) \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u00abgetForm()\u00bb.<\/p>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435.<\/h5>\n<p>  \u0420\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0444\u043e\u0440\u043c\u044b:  <\/p>\n<pre><code class=\"php\">$formModel = new RegistrationForm(); $form = $formModel-&gt;getForm(); echo $form; <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b.  <\/p>\n<pre><code class=\"php\">$user = new User(); $user-&gt;setAttributes($formModel-&gt;getAttributes()); $result = $user-&gt;save(); <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0451, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u041e\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f.    \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\/155127\/\"> http:\/\/habrahabr.ru\/post\/155127\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041f\u0440\u0438\u0432\u0435\u0442 \u0445\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440\u044b!<\/p>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 Yii \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0432\u0438\u0434\u0435\u043b, \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0431\u044b\u043b\u0430 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0441\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u0433\u0434\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0444\u043e\u0440\u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 \u0432\u0438\u0434\u0430 \u0447\u0435\u0440\u0435\u0437 \u0432\u0438\u0434\u0436\u0435\u0442 ActiveForm. \u0414\u0430, \u044d\u0442\u043e \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0444\u043e\u0440\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u0448\u0430\u0431\u043b\u043e\u043d. \u041d\u043e \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0444\u043e\u0440\u043c \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u044b.  <\/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-155127","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/155127","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=155127"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/155127\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}