CakePHPã®FormHelperã®GETã¡ã½ããã¨POSTã¡ã½ããã®éãã§ã¯ã¾ã£ã件
ãã«ãã¦ã³ãã©ã¸ãªãã¿ã³ããã§ãã¯ããã¯ã¹ã¨ãããã¹ãå
¥åãçµã¿åããããã¡ãã£ã¨è¤éãªæ¤ç´¢ç»é¢ãä½ã£ã¦ããæã«ã¯ã¾ãã¾ããã
ã»ã¨ãã©ããã©ã¼ã ã®å
¥åå¤ãANDæ¤ç´¢ããã ãã ã£ãã®ã§postConditions()ã使ã£ã¦ä½ã£ã¦ã¾ããã
æ¤ç´¢ç»é¢ãªã®ã§GETã¡ã½ããã§ã¨æã£ã¦å¤æ´ããããçæãããinputè¦ç´ ã®nameå±æ§ã®ãã©ã¼ããããå¤ãã£ã¦ãã¾ããpostConditions()ã使ããªãå½¢ã«ãªã£ã¦ãã¾ãã¾ããã
確ãã«"post"Conditions()ã£ã¦ã¡ã½ããã ãã©ãFormHelperã®æ¹ãGETã¡ã½ããã¨POSTã¡ã½ããã§åããå¤ããã¨ã¯äºæ³ãã¦ãã¾ããã§ããã
ä¸å¿ãç¡çãããªåé¿çãæ¸ãã¦ã¿ã¾ããããæ£æ»æ³ãè¯ãæ¹æ³ãç¥ã£ã¦ã人ããããæãã¦ã»ããã§ãã
POSTã¡ã½ããã®å ´å
<?php $this->Form->create(array('type'=>'post')); echo $this->Form->input('ModelA.foo'); echo $this->Form->input('ModelB.bar'); echo $this->Form->input('ModelA.ModelB.baz'); echo $this->Form->input('ModelA.ModelB.ModelC.qux'); echo $this->Form->input('ModelA.ModelB.ModelC.ModelD.quux');
<div class="input text"> <label for="ModelAFoo">Foo</label> <input name="data[ModelA][foo]" type="text" id="ModelAFoo" /> </div> <div class="input text"> <label for="ModelBBar">Bar</label> <input name="data[ModelB][bar]" type="text" id="ModelBBar" /> </div> <div class="input text"> <label for="ModelAModelBBaz">Baz</label> <input name="data[ModelA][ModelB][baz]" type="text" id="ModelAModelBBaz" /> </div> <div class="input text"> <label for="ModelAModelBModelCQux">Qux</label> <input name="data[ModelA][ModelB][ModelC][qux]" type="text" id="ModelAModelBModelCQux" /> </div> <div class="input text"> <label for="ModelAModelBModelCModelDQuux">Quux</label> <input name="data[ModelA][ModelB][ModelC][ModelD][quux]" type="text" id="ModelAModelBModelCModelDQuux" /> </div>
POSTã¡ã½ããã®å ´åãnameå±æ§ã¯ data[Model][field] ã®æ§ãªãã©ã¼ãããã§çæããã¾ãã
data[ModelA][ModelB][baz] ã®æ§ã«ãã¢ã½ã·ã¨ã¼ã·ã§ã³ã®è¡¨ç¾ãåºæ¥ã¾ãã
GETã¡ã½ããã®å ´å
<?php $this->Form->create(array('type'=>'get')); echo $this->Form->input('ModelA.foo'); echo $this->Form->input('ModelB.bar'); echo $this->Form->input('ModelA.ModelB.baz'); echo $this->Form->input('ModelA.ModelB.ModelC.qux'); echo $this->Form->input('ModelA.ModelB.ModelC.ModelD.quux');
<div class="input text"> <label for="ModelAFoo">Foo</label> <input name="foo" type="text" id="ModelAFoo" /> </div> <div class="input text"> <label for="ModelBBar">Bar</label> <input name="bar" type="text" id="ModelBBar" /> </div> <div class="input text"> <label for="ModelAModelBBaz">Baz</label> <input name="ModelB[baz]" type="text" id="ModelAModelBBaz" /> </div> <div class="input text"> <label for="ModelAModelBModelCQux">Qux</label> <input name="ModelC[qux]" type="text" id="ModelAModelBModelCQux" /> </div> <div class="input text"> <label for="ModelAModelBModelCModelDQuux">Quux</label> <input name="" type="text" id="ModelAModelBModelCModelDQuux" /> </div>
GETã¡ã½ããã«ããå ´åãã¢ãã«åãæ¸ãã¦ãç¡è¦ãã㦠foo ã bar ã®ã¿ã«ãªãã¾ãã
å½ç¶ã¢ã½ã·ã¨ã¼ã·ã§ã³ã®è¡¨ç¾ãåºæ¥ã¾ããããã¢ãã«ã2ã3å並ã¹ãå ´åã®ã¿ãè¥å¹²POSTã¡ã½ããã®æã¨ä¼¼ãåºåã§ãã
ãã 4å以ä¸ã®ã¢ãã«ã並ã¹ããã空æåã«ãªã£ã¦ãã¾ã£ãã®ã§ãã¢ãã«åãæ¸ãäºèªä½ãæ³å®å¤ãªãã§ãããã
åé¿ç
<?php $this->Form->create(array('type'=>'get')); echo $this->Form->input('data[ModelA][foo]'); echo $this->Form->input('data[ModelB][bar]'); echo $this->Form->input('data[ModelA][ModelB][baz]'); echo $this->Form->input('data[ModelA][ModelB][ModelC][qux]'); echo $this->Form->input('data[ModelA][ModelB][ModelC][ModelD][quux]');
<div class="input text"> <label for="JobofferData[ModelA][foo]">Data[model A][foo]</label> <input name="data[ModelA][foo]" type="text" id="JobofferData[ModelA][foo]" /> </div> <div class="input text"> <label for="JobofferData[ModelB][bar]">Data[model B][bar]</label> <input name="data[ModelB][bar]" type="text" id="JobofferData[ModelB][bar]" /> </div> <div class="input text"> <label for="JobofferData[ModelA][ModelB][baz]">Data[model A][model B][baz]</label> <input name="data[ModelA][ModelB][baz]" type="text" id="JobofferData[ModelA][ModelB][baz]" /> </div> <div class="input text"> <label for="JobofferData[ModelA][ModelB][ModelC][qux]">Data[model A][model B][model C][qux]</label> <input name="data[ModelA][ModelB][ModelC][qux]" type="text" id="JobofferData[ModelA][ModelB][ModelC][qux]" /> </div> <div class="input text"> <label for="JobofferData[ModelA][ModelB][ModelC][ModelD][quux]">Data[model A][model B][model C][model D][quux]</label> <input name="data[ModelA][ModelB][ModelC][ModelD][quux]" type="text" id="JobofferData[ModelA][ModelB][ModelC][ModelD][quux]" /> </div>
ãããç¡çããæãããã¾ãããããã§ä½ã¨ããªãã¾ãã
ãã¾ãããããã¦ãã¦ã¯ä½¿ããããªããã§ããã©ãã»ã»ã»
$this->data ã¨åããããªé åã $this->params['url']['data'] ã«æ ¼ç´ããã¾ãã
<?php echo $this->Form->input('data[ModelA][foo]', array('multiple'=>'checkbox', 'options'=>$fooArray, 'label'=>'Foo'));
ãã®æ¹æ³ã§ãã§ãã¯ããã¯ã¹ã®æ§ãªé
åã«ãªãå
¥åããGETã¡ã½ããã§éä¿¡ã§ãã¾ããã
ã©ãã«ãã²ã©ãäºã«ãªã£ã¡ããã®ã§ãlabel ãªãã·ã§ã³ã¯æ¼ããªãè¨å®ããæ¹ãããããã§ãã
postConditions()ã¨ã¯
ãã©ã¼ã ããéããã¦ãããã¼ã¿ããã¢ãã«ã®findãªã©ã®æ¤ç´¢æ¡ä»¶ conditions ã®å½¢ã«å¤æãã¦ããã Controller->postConditions() ã¨ãã便å©ãªã¡ã½ãããããã¾ãã
<?php Array ( [Model] => Array ( [foo] => bar [baz] => qux [quux] => Array ( [0] => corge [1] => grault ) ) )
POSTããããã¼ã¿ã¯ãããªé åã¨ãã¦ã³ã³ããã¼ã©ã¼ã® $this->data ã«å ¥ã£ã¦ã¾ãã
$this->postConditions($this->data)
<?php Array ( [Model.foo] => bar [Model.bar] => qux [Model.quux] => Array ( [0] => corge [1] => grault ) )
postConditions() ã§ãã®ãã㪠Model->find() ã® conditions ãªãã·ã§ã³ã¨ãã¦ä½¿ããé åã«ä½ãç´ãã¦ããã¾ãã