表单中的值取决于URL

时间:2011-09-28 22:40:28

标签: php symfony1 doctrine symfony-1.4

的schema.yml:

店铺:   title:{type:string(50)}   number:{type:integer(2)}

我可以在ShopForm.class中设置数字的默认值或方法保存。但我如何使用地址网址?

http://www.myaddress.com/shop/new

action.class.php(Shop.class.php)

中的

public function executeNew(sfWebRequest $request)
  {
    $this->form = new ShopForm();
  }

例如,如果我打开地址:

http://www.myaddress.com/shop/new/number/2

然后自动为此表单设置number = 2.

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您可以在新操作中捕获参数:

$this->number = $request->getParameter('number');

这样做可以访问模板中的$number变量(构建表单的位置)。然后在您指定数字值的表单字段中,只需输入如下内容:

<input type="whatever" name="number" value="<?php echo $number?>">
希望这对你有所帮助!祝你好运