Search code examples
formsvariablessymfony-1.4models

Symfony: Pass an object from another module to a form


I have a symfony project and I have one model, which for this example I will name Boat. From the Boat's showSuccess page, I would like to make a link to another model's form page. For this example we will call it Ticket. When they click on the link, I would like for the Boat object to be passed to the Ticket form because I have to display some of that specific Boat's fields (title, price, etc) on the Ticket form page (newSuccess.php).

I guess my question is, how do I pass an object (as a variable) to another model's "new" form page. I have looked everywhere and I can't seem to find an answer that works for me. Thank you!

UPDATE:

Here is some of the code I've tried:

Routing.yml

ticket_new_car:
  url:     /ticket/:category/:iditem
  class:   sfDoctrineRoute
  options: { model: car, type: object }
  param:   { module: ticket, action: new }
  requirements:
    id: \d+
    sf_method: [get]

Link on Car page

<a href="<?php echo url_for('ticket_new_car', $car)?>" > Test </a>

actions.class.php

public function executeNew(sfWebRequest $request)
  {
    $this->item = $this->getRoute()->getObject();
    $this->forward404Unless($this->item);
    $this->form = new TicketForm();
  }

_form.php

<?php echo $item->getTitle() ?>

I'm getting "Undefined variable: item". I did everything in the tutorial except for the "slug" part because I'm not slugging my URLs. What could I be doing wrong?


Solution

  • Look at this page

    http://www.symfony-project.org/jobeet/1_4/Doctrine/en/05#chapter_05_object_route_class

    And scroll down to Object Route Class