0

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?

GoRivera
  • 173
  • 1
  • 13

1 Answers1

0

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

j0k
  • 22,600
  • 28
  • 79
  • 90
ilSavo
  • 854
  • 1
  • 8
  • 28
  • Thank you for the link. See updated question above to see the code that I tried and see what I'm doing wrong. – GoRivera Oct 19 '12 at 01:34
  • In routing.yml file, try to write "Car" instead of "car", in options row...so, before `options: { model: car, type: object }` --> after `options: { model: Car, type: object }` – ilSavo Oct 22 '12 at 10:03
  • I found what my problem was. I wasn't passing the variable to the `_form.php` partial. As soon as I updated to ` $form, 'item' => $item)) ?>` in the `newSuccess.php` file, it passed the variable and now I'm able to display the fields on that page. Now the problem I'm having is that it doesn't seem to pass the variable from action to action. I want it to be able to save the `$item->getCategory` to the `$form->setCategory` and it seems like it doesn't pass the variable to the `save` action. What's an easy way to do that? – GoRivera Oct 24 '12 at 03:09
  • I found this link that solved my problem. I'm not sure if saving it to the session is really safe but it helped me do what I needed to do. [http://stackoverflow.com/questions/5229494/symfony-pass-parameter-between-actions-with-a-redirect](http://stackoverflow.com/questions/5229494/symfony-pass-parameter-between-actions-with-a-redirect) – GoRivera Oct 26 '12 at 01:06