0

I have two models namely 'Client' and 'Pet' which have admin generated modules for each. There is a one-to-many relationship involved so I want to be able to create a new Pet using a cid (client id) specified in the URL (i.e. /pet/new/cid/6)

I already disabled the cid field in the Client form so that the parameter from the URL will be passed as the default value.

I tried overriding the actions.class.php of the admin generated module with this code:

public function executeCreate(sfWebRequest $request)
{
    $this->form = $this->configuration->getForm();
    $params = $request->getParameter($this->form->getName());
    $params["cid"] = $request->getParameter('cid');
    $request->setParameter($this->form->getName(), $params);

    parent::executeCreate($request);
}

It works if i replaced

$request->getParameter('cid');

with a hard-coded int value so I think the problem is that I'm not able to get the parameter from the URL.

I think I might be missing on some routing configurations but I'm fairly new to this framework so I'm not really sure what to do.

1 Answers1

0

You can simply pass the parameter cid in the url like this :
/pet/new?cid=6

and get the result in your action with :
$request->getParameter('cid');

The first part of the routing (/pet/new) is a specific doctrineRouteCollection

dxb
  • 931
  • 5
  • 7
  • I tried accessing that URL and it's giving me this error: 404 | Not Found | sfError404Exception Action "pet/show" does not exist. – beenalee May 04 '11 at 04:57
  • Don't use show action, it's not implemented in the admingen. Try again with an url like this /pet/new?cid=6 – dxb May 04 '11 at 08:03