On Apr 16, 7:32 am, mivogt-LU <[email protected]> wrote:
> HI there,
>
> I did a mod to my add function in a model/controller.
>
> My model-1 view now has a button calling the add function of model-2
> sending some parameters to be shown in the add view.
>
> Now I want the model-2 to disable any add function inside the
> conroller if no data was passed from model-1 (or via url).
>
> Is there a best practise solution or is it ok just to do something
> like the check done for id when deleting a record?:
>         function edit($id = null) {
>                 if (!$id && empty($this->data)) {
>                         $this->Session->setFlash(sprintf(__('Invalid %s', 
> true),
> 'booking'));
>                         $this->redirect(array('action' => 'index'));

That would work except that you're expecting that $id will always be
present in the URL. So you'll need to make sure it is (in links or
form actions). Or, you could change it to:

if (!$id || empty($this->data['ModelName']
['some_var_from_other_view']))

But that would still allow someone to access this method without going
to the other view. So, maybe:

if (empty($this->data['ModelName']['some_var_from_other_view']))

That's edit() not add() btw (not that it matters).


> Additional question I want to redirect to the calling model-1.
> Hot to call model-1-index instead of model-2-index as shown?

$this->redirect(array('controller' => 'the_other_controller', 'action'
=> 'index'));

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to