cakephp - Better solution for non-model request on CakePHP1.3 -


there parameter withought relayting model.

router::connect("/ctrl/action/:mode/:year"      ,     array('controller' => 'ctrl', 'action' => 'action'),     array('mode' => 'modea|modeb', 'year' => '[12][0-9]{3}')); 

how validate , sanitize?

should create dummy model? or implement on component?

well, current route wouldn't match /ctrl/action/modea/5010, fall through route, standard route, dispatch request ctrl_controller::action('modea', 5010). i.e. have same result.

the best thing skip route, since doesn't route anywhere wouldn't go anyway. validate in controller action before using values:

function action($mode, $year) {     if (!in_array($mode, array('modea', 'modeb')) || $year < 1900 || 3000 < $year) {         $this->cakeerror('error404');     }     ... business usual ... } 

or:

function action($mode, $year) {     switch ($mode) {         case 'modea' :             ...             break;         case 'modeb' :             ...             break;         default :             $this->cakeerror('error404');     } } 

or combination thereof. unless $mode , $year variables have database/model, not want make model it. models validation, because that's important step before putting stuff database, doesn't mean they're part of app can or should validation.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -