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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -