Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthoromagro
    • CommentTimeFeb 22nd 2008
     
    I have a model called organization and this has many producers, I want
    to pass the id of organization to the organization_id on producer when
    I'm adding a new producer to the current organization?
    How can I do this, please help (I'm a newbie of course)
    My add function look like this
    function add()
    {
    if(!empty($this->params['producer'])){
    $this->Producer->setAttributes($this->params['producer']);
    $this->Producer->organization_id = $this->organization-
    >get('id'); // this is obviously not working what can I do

    if ($this->Request->isPost() && $this->Producer->save()){
    $this->flash['notice'] = $this->t('Producer was
    successfully created.');
    $this->redirectTo(array('action' => 'show', 'id' =>
    $this->producer->getId()));
    }
    }
    }
    Do I need to add anything to the producer model???
    • CommentAuthorsuthern
    • CommentTimeFeb 22nd 2008 edited
     

    I assume that when you are creating the input forms, you have the organization ID availible. If so, then simply put it in a hidden field inside the form (the _form.tpl inside your views/producer/ folder), and fill it's 'value' with the 'organization_id'. Something like this:

     <?php echo $form_helper->hidden_field('producer','organization_id',array('value' => $organization->id )); ?>
    

    Everything in the form is transferred to the database when you do a SAVE (as long as the field name is correct).

    • CommentAuthorThijs
    • CommentTimeFeb 22nd 2008 edited
     

    Another way: you could make a 'add producer to organisation' action in the organisation controller.

    That way you could pass the ID of the organisation with a special route.

    $Map->connect('/organisation/:id/producer/', array(
    'controller' => 'organisation',
    'action' => 'add_producer'
    ));
    

    and in the organisation controller:

    function add_producer(){ 
    
       if(!empty($this->params['producer'])){
    
          $this->Producer->setAttributes($this->params['producer']); 
          $this->Producer->organization_id = $this->params['id'];
    
          if ($this->Request->isPost() && $this->Producer->save()){ 
             $this->flash['notice'] = $this->t('Producer was successfully created.'); 
             $this->redirectTo(array('action' => 'show', 'id' => $this->producer->getId())); 
          } 
       } 
    } 
    

    .. or something like that

Add your comments
    Username Password
  • Format comments as