2008”N05ŒŽ20“ú

‚»‚¤‚��‚¦‚΁AView‚ɂ‚��‚Ä‚Í‚ ‚Ü‚èŒê‚ç‚ê‚��‚Ȃ��

‚»‚¤‚��‚¦‚΁A‚¾‚ê‚àViewƒNƒ‰ƒX‚ɂ‚��‚Ä‚Í‚ ‚܂葽‚­‚ðŒê‚Á‚��‚Ü‚¹‚ñ‚ˁB$this->set()‚Ńrƒ…[‚Ƀf[ƒ^‚ð‘—‚éˆÈŠO‚́A’P‚È‚éhtml‚È‚ñ‚��‚á‚Ȃ��‚́H‚Ƃ��‚¤º‚à•·‚�}‚¦‚Ä‚«‚»‚¤‚Å‚·B

‚µ‚©‚µA1.1‚ÌView‚̃Rƒ“ƒXƒgƒ‰ƒNƒ^‚ɂ͂�}‚ñ‚ȃR[ƒh‚ª“ü‚Á‚��‚Ü‚µ‚½B


function __construct(&$controller) {
if(is_object($controller)){
$this->controller =& $controller;
$this->_viewVars = $this->controller->_viewVars;
$this->action = $this->controller->action;
$this->autoLayout = $this->controller->autoLayout;
$this->autoRender = $this->controller->autoRender;
$this->base = $this->controller->base;
$this->webroot = $this->controller->webroot;
$this->helpers = $this->controller->helpers;
$this->here = $this->controller->here;
$this->layout = $this->controller->layout;
$this->modelNames = $this->controller->modelNames;
$this->name = $this->controller->name;
$this->pageTitle = $this->controller->pageTitle;
$this->viewPath = $this->controller->viewPath;
$this->params = $this->controller->params;
$this->data = $this->controller->data;
$this->webservices = $this->controller->webservices;
$this->plugin = $this->controller->plugin;
}
parent::__construct();
}


1.2‚Å‚Í”z—ñ‚Őݒ肳‚ê‚��‚Ü‚·B


var $__passedVars = array('viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot', 'helpers', 'here', 'layout', 'name', 'pageTitle', 'layoutPath', 'viewPath', 'params', 'data', 'webservices', 'plugin', 'passedArgs', 'cacheAction');

$count = count($this->__passedVars);
for ($j = 0; $j < $count; $j++) {
$var = $this->__passedVars[$j];
$this->{$var} = $controller->{$var};
}



View‚ÌHTML‚Ì’†‚Å‚àA‚©‚È‚è‚̃f[ƒ^‚ɃAƒNƒZƒX‚Å‚«‚Ü‚·B‚¤‚Ü‚­Šˆ—p‚Å‚«‚é‚Æ‚È‚©‚È‚©•Ö—˜‚Å‚·‚ˁB
ƒ‰ƒxƒ‹Fcakephp view
posted by SDozono at 14:03| “Œ‹ž ☔| Comment(0) | TrackBack(0) | CakePHP View | ‚}‚̃uƒƒO‚Ì“ÇŽÒ‚É‚È‚é | XVî•ñ‚ðƒ`ƒFƒbƒN‚·‚é

2006”N07ŒŽ19“ú

’l‚̃`ƒFƒbƒN‚ɂ܂‚í‚é‚��‚ë‚��‚ë

“ü—Í‚³‚ꂽƒf[ƒ^‚̃`ƒFƒbƒN•û–@‚ÉŠÖ‚µ‚ẮA

http://manual.cakephp.org/chapter/12

‚�}‚�}‚ɂ��‚ë‚��‚ëà–¾‚ª‚ ‚è‚Ü‚·B“ú–{ŒêŠÖŒW‚Ì‚à‚̂́AŽ©•ª‚ł��‚ë‚��‚ëÝ’è‚Å‚«‚Ü‚·B

‚ŁA‚�}‚�}‚Őݒ肵‚½ƒ`ƒFƒbƒNƒ‹[ƒ‹‚ª‚ǂ�}‚Å—˜—p‚³‚ê‚é‚©A‚Ƃ��‚¤‚ƁA

‚Pjã‹L‚̃}ƒjƒ…ƒAƒ‹‚É‚ ‚é‚悤‚ɁA
@@@ if($this->Post->validates($this->data))
‚Æ‚·‚ê‚΁A$this->data ‚Å‘—‚ç‚ꂽ“ü—̓f[ƒ^‚ªAPost ƒ‚ƒfƒ‹‚̐ݒ胋[ƒ‹‚É“K‡‚µ‚��‚é‚©ƒ`ƒFƒbƒN‚Å‚«‚Ü‚·B³‚µ‚¯‚ê‚Î true ‚ª•Ô‚Á‚Ä‚«‚Ü‚·B
‚�}‚ê‚́Aƒ‚ƒfƒ‹‚É‚ ‚郁ƒ\ƒbƒh‚Å‚ ‚é‚�}‚Æ‚É’ˆÓB

‚Qj‚»‚ꂼ‚ê‚Ì’l‚̂ǂꂪ‚�N‚©‚µ‚��‚Ì‚©’²¸EÝ’肳‚¹‚é‚ɂ́A
@@@@$this->validateErrors($this->User);
@‚Æ‚µ‚Ü‚·B‚�}‚ê‚́AgƒRƒ“ƒgƒ[ƒ‰‚̃ƒ\ƒbƒhh‚Å‚ ‚é‚�}‚Æ‚É’ˆÓ‚µ‚Ü‚µ‚傤B‚�}‚̍ì‹Æ‚ł́A‚ ‚郂ƒfƒ‹‚̃f[ƒ^‚ð‚ЂƂˆê‚ƒ`ƒFƒbƒN‚µAƒ‹[ƒ‹‚É‚ ‚Ä‚Í‚Ü‚ç‚Ȃ��‚à‚Ì‚ª‚ ‚ê‚΁A‚»‚́gƒXƒCƒbƒ`‚ðƒpƒ`ƒb‚Æ“ü‚ê‚éh‚悤‚È“®ì‚ð‚µ‚Ü‚·B‚‚܂è‚́Aƒ‚ƒfƒ‹‚Ì invalidate ‚Ƃ��‚¤ƒƒ\ƒbƒh‚ðŽÀs‚µA$this->validationErrors[$field] ‚Ƃ��‚¤”z—ñ‚ð 1iƒXƒCƒbƒ`EƒIƒ“Ij‚ɐݒ肵‚Ü‚·B

‚Rj$this->Property->save($this->data['Property'])

‚Ȃǂ̂悤‚É‚µ‚āAƒ‚ƒfƒ‹‚Ìsaveƒƒ\ƒbƒhi“ü—Í‚³‚ꂽƒf[ƒ^j
‚ðŽÀs‚·‚é‚ƁAŽ©“®“I‚É validateErrors ‚̃`ƒFƒbƒN‚ª‚©‚©‚è‚Ü‚·Bi‚Q‚Æ“¯‚��Bj‹­ï¿½ï¿½“I‚ɕۑ��‚µ‚½‚��ê‡‚ɂ́A

$this->Property->save($this->data['Property'], false)

‚Æ‚·‚ê‚΁Aƒ`ƒFƒbƒN‚𖳎‹‚Å‚«‚Ü‚·B

‚SjŽ©‘O‚ŁAg‚�}‚Ì’l‚Í‚¾‚ß‚¾‚æƒ`ƒFƒbƒNh‚ð‚µ‚½‚��ê‡‚ɂ́A

if(ƒ`ƒFƒbƒN‚ª’Ê‚ç‚È‚©‚Á‚½ê‡){
$this->User->invalidate('username');@//gƒGƒ‰[ƒXƒCƒbƒ`h‚ðONB
}

‚Æ‚·‚ê‚΁A username ‚Ƃ��‚¤ƒtƒB[ƒ‹ƒh‚̃f[ƒ^‚Í’Ê‚ç‚È‚©‚Á‚½‚�}‚Æ‚É‚È‚è‚Ü‚·B‚�}‚�}‚Å•¡”ðŒ‚Ń`ƒFƒbƒN‚µ‚½‚��AƒGƒ‰[ƒƒbƒZ[ƒW‚ð•Ï‚¦‚½‚��A‚Ȃǂ̏ꍇ‚ɂ́Ausername_hiragana ‚Ȃǂ̂悤‚ɁAŽ©•ª‚ŏŸŽè‚ɍì‚Á‚Ä‚µ‚Ü‚Á‚Ä‘åä•v‚Å‚·B

‚TjView ‚ł̃Gƒ‰[•\Ž¦
@@@$html->tagErrorMsg('Post/title', 'ƒ^ƒCƒgƒ‹‚ð‹L“ü‚µ‚Ä‚­‚¾‚³‚��')

@@‚Ƃ��‚¤Œ`‚ðŽg‚��‚Ü‚·B—Ⴆ‚Ώã‚̏ꍇ‚ɂ́A"Postƒf[ƒ^‚Ìtitle‚Ƃ��‚¤–¼‘O‚̃tƒ‰ƒO‚ª—��‚Á‚��‚ê‚΁AƒGƒ‰[‚ð•\Ž¦‚·‚é"‚Ƃ��‚¤‚�}‚Æ‚É‚È‚è‚Ü‚·B
‘�}‚¯‚āA

@@@$html->tagErrorMsg('Post/title_hiragana', 'ƒ^ƒCƒgƒ‹‚͂Ђ炪‚È‚Å‹L“ü‚µ‚Ä‚­‚¾‚³‚��')

‚È‚Ç‚à•À‚�~‚�N‚¯‚΁A $this->Post->invalidate('title_hiragana')@‚ð‚µ‚Ä‚ï¿½ï¿½‚½ê‡‚É‚Í•\Ž¦‚³‚ê‚é‚�}‚Æ‚É‚È‚è‚Ü‚·B

‚¿‚Ȃ݂ɁA

E Model ƒNƒ‰ƒX‚Ì’†‚ɂ́A
@@validates,@@@@ƒ`ƒFƒbƒN‚ª’Ê‚Á‚½‚ç True ‚ð•Ô‚·B
@@invalidFields,@@ƒ`ƒFƒbƒN‚Ɉø‚Á‚©‚©‚Á‚½”z—ñ‚ð•Ô‚·B
@@invalidate@@@@ƒ`ƒFƒbƒN‚ª’Ê‚ç‚È‚©‚Á‚½‚ ‚鍀–ڂ̃XƒCƒbƒ`‚ð‚n‚mB
‚Ƃ��‚¤ƒƒ\ƒbƒhB

E Controller ƒNƒ‰ƒX‚Ì’†‚ɂ́A
@@validate, ƒGƒ‰[‚́g”h‚ð•Ô‚·B
@@validateErrors@@ƒGƒ‰[‚Ì‚ ‚éƒf[ƒ^‚𒲍¸AƒXƒCƒbƒ`‚ð“ü‚ê‚Ä‚ä‚­B
‚Ƃ��‚¤ƒƒ\ƒbƒhB

‚Ƃ��‚¤Ž—‚Ä”ñ‚È‚é–½—ß‚ª‚ ‚è‚Ü‚·‚̂ŁAŽg‚��•ª‚¯‚É’ˆÓ‚µ‚Ü‚µ‚傤B
@@

@



posted by SDozono at 12:33| ƒƒTƒ“ƒ[ƒ‹ƒX 🌁| Comment(0) | TrackBack(0) | CakePHP View | ‚}‚̃uƒƒO‚Ì“ÇŽÒ‚É‚È‚é | XVî•ñ‚ðƒ`ƒFƒbƒN‚·‚é