Hi Rich

Thanks for that !! One more question..
If I want to change the
($this->UserFavourite->save($this->data)) {

where the controller gets the info from the view..
                echo $form->input('user_id');
                echo $form->input('item_id');

I want the controller not to go the the 'add' view but just add user
(in the session)($session->read('Auth.User.id')), to db, and also the
item_id which will be given in the URL like so:
testsite/user_favourites/add/2

Any idea how to do this??

Regards



On Fri, Sep 26, 2008 at 7:02 PM, Donkeybob <[EMAIL PROTECTED]> wrote:
>
> You use it the way you have it and just change the section in the add
> function to redirect . . .
>
> -> $this->redirect(array('action'=>'view'));
>
> Every function should have a related view file unless you state
> otherwise with a layout call.
>
> if your action is "add" then you have to have an add function in the
> controller, which uses the add view. . . .just redirect it in your
> statement.
>
> function add() {
>                if (!empty($this->data)) {
>                        $this->UserFavourite->create();
>                        if ($this->UserFavourite->save($this->data)) {
>                                $this->Session->setFlash(__('The
> UserFavourite has been saved', true));
>                                $this-
>>redirect(array('action'=>'view'));
>                        } else {
>                                $this->Session->setFlash(__('The
> UserFavourite could not be saved. Please, try again.', true));
>                                $this-
>>redirect(array('action'=>'view'));
>                        }
>                }
>        }
>
>
> hope this is a start
> rich
>
>
> On Sep 26, 10:59 am, gabriel <[EMAIL PROTECTED]> wrote:
>> Hi, does anyone know how I can add  (like a favourite to a db table)
>> without going to the add view?
>>
>> I have a link
>> testsite/user_favourites/add/2
>>
>> IF I click on it it, it takes me to the add view (which has a model
>> and controller)
>> I DON'T want to go to the add view, but the 'view' view which shows
>> the favourite that had just been added... here is the add controller
>> and view and model
>>
>> ////////////////////////////////////////////////////
>> controller /////////////////////////////////
>>         function add() {
>>                 if (!empty($this->data)) {
>>                         $this->UserFavourite->create();
>>                         if ($this->UserFavourite->save($this->data)) {
>>                                 $this->Session->setFlash(__('The 
>> UserFavourite has been saved',
>> true));
>>                                 $this->redirect(array('action'=>'index'));
>>                         } else {
>>                                 $this->Session->setFlash(__('The 
>> UserFavourite could not be saved.
>> Please, try again.', true));
>>                         }
>>                 }
>>                 $users = $this->UserFavourite->User->find('list');
>>                 $this->set(compact('users'));
>>         }
>>
>> ////////////////////////////////////////////
>> model//////////////////////////////////////////////////
>> class UserFavourite extends AppModel {
>>
>>         var $name = 'UserFavourite';
>>         var $validate = array(
>>                 'id' => array('numeric'),
>>                 'user_id' => array('numeric'),
>>                 'item_id' => array('numeric')
>>         );
>>
>>         //The Associations below have been created with all possible keys,
>> those that are not needed can be removed
>>         var $belongsTo = array(
>>                         'User' => array('className' => 'User',
>>                                                                 'foreignKey' 
>> => 'user_id',
>>                                                                 'conditions' 
>> => '',
>>                                                                 'fields' => 
>> '',
>>                                                                 'order' => ''
>>                         )
>>         );
>>
>> }
>>
>> ///////////////////////////////////////
>> view//////////////////////////////////////////////////////////////////
>> <div class="userFavourites form">
>> <?php echo $form->create('UserFavourite');?>
>>         <fieldset>
>>                 <legend><?php __('Add UserFavourite');?></legend>
>>         <?php
>>                 echo $form->input('user_id');
>>                 echo $form->input('item_id');
>>         ?>
>>         </fieldset>
>> <?php echo $form->end('Submit');?>
>> </div>
>> <div class="actions">
>>         <ul>
>>                 <li><?php echo $html->link(__('List UserFavourites', true),
>> array('action'=>'index'));?></li>
>>                 <li><?php echo $html->link(__('List Users', true),
>> array('controller'=> 'users', 'action'=>'index')); ?> </li>
>>                 <li><?php echo $html->link(__('New User', true),
>> array('controller'=> 'users', 'action'=>'add')); ?> </li>
>>         </ul>
>> </div>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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