php - When parameter is not passed to controller over url -
in cakephp, i've controller should receive parameter , call model work database show result in view. pretty common mvc approach.
imagine controller "insert new post" should associated specific user.
so, url should be: http://mysite/inspost/(user_id).
the problem is, when url http://mysite/inspost/
it show same view , insert new post if user_id has not been specified.
how can control this?
from 2nd page of blog tutorial, adding layer:
public function view($id = null) { if (!$id) { throw new notfoundexception(__('invalid post')); } $post = $this->post->findbyid($id); if (!$post) { throw new notfoundexception(__('invalid post')); } $this->set('post', $post); }
Comments
Post a Comment