value in form dependent on URL
schema.yml:
Shop: title: { type: string(50) } number: { type: integer(2) }
i can set default value for number in ShopForm.class or method save. but how can i make it with address URL?
http://www.myaddress.com/shop/new
in action.class.php (Shop.class.php)
public function exe开发者_Python百科cuteNew(sfWebRequest $request)
{
$this->form = new ShopForm();
}
for example if i open address:
http://www.myaddress.com/shop/new/number/2
then automatically set number = 2 for this form.
thanks for help!
you can catch the parameter in the New Action doing this:
$this->number = $request->getParameter('number');
Doing that you can access to the $number
variable in your template (where you build your form). Then in the form field where you specify the number value, just put something like this:
<input type="whatever" name="number" value="<?php echo $number?>">
hope this helped you! good luck
精彩评论