{"id":181642,"date":"2013-05-31T13:47:03","date_gmt":"2013-05-31T09:47:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=181642"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=181642","title":{"rendered":"<span class=\"post_title\">\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432 Yii<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412\u0441\u0435 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441 \u043d\u043e\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0442 Zend \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 Yii. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0430 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0444\u043e\u0440\u043c\u0435. \u041f\u043e\u0441\u043b\u0435 \u043a\u043e\u0432\u044b\u0440\u044f\u043d\u0438\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041f\u043e\u0435\u0445\u0430\u043b\u0438:<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c \u0431\u044b\u043b\u043e 2. \u041f\u0435\u0440\u0432\u043e\u0435 \u044d\u0442\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432 \u2014 \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u043c\u043e\u0433 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f wizard-behavior (http:\/\/www.yiiframework.com\/extension\/wizard-behavior). \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0432, \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0430 \u043e\u0434\u0438\u043d action \u0438 \u043e\u0434\u043d\u0443 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432. <br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u0441\u0434\u0435\u043b\u0430\u043b \u0447\u0435\u0440\u0435\u0437 ajax \u0447\u0435\u0440\u0435\u0437 render-partial \u0432\u044c\u044e\u0448\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u043e\u043b\u044f.<\/p>\n<p>  \u0424\u043e\u0440\u043c\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u043e view:  <\/p>\n<pre><code class=\"php\">$form=$this-&gt;beginWidget('CActiveForm', array(                     'id'=&gt;'create_order_step1',                     'enableClientValidation'=&gt;true,                     'clientOptions'=&gt;array(                         'validateOnSubmit'=&gt;true,                         'validateOnType' =&gt; true,                     ),));  <\/code><\/pre>\n<p>  \u0412 \u043d\u0435\u0439 \u0436\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439:  <\/p>\n<pre><code class=\"php\">echo CHtml::button('\u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e', array('class' =&gt; 'place-add btn')); &lt;script&gt; $(&quot;.place-add&quot;).click(function(){     var index = $(&quot;.new-place&quot;).size()+1;       \/\/\/ \u0441\u0447\u0438\u0442\u0430\u0435\u043c  \u043a\u043e\u043b-\u0432\u043e \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 \u0441 \u043f\u043e\u043b\u044f\u043c\u0438.      $.ajax({         success: function(html){             $(&quot;#add_place&quot;).append(html);      \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u043e \u0432\u044c\u044e \u043d\u0430\u0448\u0438 \u043f\u043e\u043b\u044f.         },         type: 'get',         url: '\/index.php\/site\/field',      \/\/ \u0434\u0435\u043b\u0430\u0435\u043c ajax \u0437\u0430\u0440\u043e\u0441 \u043a action         data: {             index: index         },         cache: false,         dataType: 'html'     }); }); &lt;\/script&gt; <\/code><\/pre>\n<p>  Action:  <\/p>\n<pre><code class=\"php\">public function actionField($index = false)     {         $model = new CreateOrderForm();         $this-&gt;renderPartial('_add_place_fields', array(             'model' =&gt; $model,             'index' =&gt; $index,         ));     } <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u0431\u043b\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c +1.<\/p>\n<p>  \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u043b\u044f:  <\/p>\n<pre><code class=\"html\">&lt;table class=&quot;new-place&quot; id=&quot;place_n&lt;?php echo$index; ?&gt;&quot;&gt;                                            &lt;tr&gt;             &lt;td&gt;                 &lt;?php                 echo CHtml::activeTextField($model, &quot;place_weight[$index]&quot;);       \/\/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u044f \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438.                 echo CHtml::error($model, &quot;place_weight[$index]&quot;);               \/\/ \u0432\u044b\u0432\u0430\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438                  ?&gt;             &lt;\/td&gt;         &lt;\/tr&gt; &lt;\/table&gt; <\/code><\/pre>\n<p>  \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c action \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e $model-&gt;validate(scenario) \/\/ \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043c\u0435\u043d\u044f\u043b\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0448\u0430\u0433\u0430.<br \/>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0430 \u0442\u043e\u0433\u0434\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u043b\u0435\u0439 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u0442\u0434\u0430\u0435\u043c \u0432\u043e \u0432\u044c\u044e. (\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u043d\u0435 \u0438\u0441\u0447\u0435\u0437\u043b\u0438)  <\/p>\n<pre><code class=\"php\">if(isset($model-&gt;attributes['place_weight'])){         $count = count($model-&gt;attributes['place_weight']); } $this-&gt;render('view', compact('model', 'count'); <\/code><\/pre>\n<p>  \u0412\u043e \u0432\u044c\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u044d\u0442\u0438 \u043f\u043e\u043b\u044f \u0442\u0430\u043a:   <\/p>\n<pre><code class=\"php\">for($i =1; $i&lt;$count; $i++){      $this-&gt;renderPartial('_add_place_fields', array(               'model' =&gt; $model,               'index' =&gt; $i,      )); } <\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"php\">public function rules()     {         return array(array('place_weight', 'validatePlace', 'on'=&gt;'step1'), );     } public function validatePlace($attribute,$params)       \/\/\u0437\u0434\u0435\u0441\u044c \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.     {         foreach($this-&gt;place_weight as $key_w =&gt; $weight){             if (empty($weight)) {                 $this-&gt;addError('place_weight['.$key_w.']', '\u041f\u043e\u043b\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e');                 break;             }         } } <\/code><\/pre>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0441\u0435. \u0414\u0443\u043c\u0430\u044e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0432 yii, \u0432\u0440\u043e\u0434\u0435 \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \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\/181642\/\"> http:\/\/habrahabr.ru\/post\/181642\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412\u0441\u0435 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441 \u043d\u043e\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0442 Zend \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 Yii. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0430 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0444\u043e\u0440\u043c\u0435. \u041f\u043e\u0441\u043b\u0435 \u043a\u043e\u0432\u044b\u0440\u044f\u043d\u0438\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041f\u043e\u0435\u0445\u0430\u043b\u0438:  <\/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-181642","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/181642","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=181642"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/181642\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}