获取symfony2控制器中select标签的选定选项的ID

时间:2012-06-04 22:41:34

标签: php symfony

我的表单只有一个选择标记。我想在用户提交表单时获取控制器中所选选项标签的ID。我的表格是

 <div class="one_third">
        <form name="portfolios" action="{{ path('MunichInnovationGroupBundle_portfolio') }}" method="post" >
            <h2>Select your portfolio</h2>
            <p>Change the portfolio to be managed:<br />
                <select name="portfolio" style="width: 265px; height:28px;">
                    <option selected="selected" value="default">Switch Your Portfolio</option>
                    {% for portfolio in portfolios %}
                        <option id={{ portfolio.id }}>{{ portfolio.portfolioName }}</option>
                        {% endfor %}
                </select>
            </p>
            <p>
                <input style="margin-left:100px; height:26px; cursor:pointer; background-color: #2D9AD3 !important; border: 1px solid #067EBD; color: #FFFFFF; text-shadow: 0 -1px 0 #067EBD;" type="submit"class="button2 tooltip" value="Switch">
            </p> 
        </form>
    </div>

在我的控制器中

if($request->getMethod() == 'POST'){
        $data = $request->request->all();
        //$portfolio_id = $data['portfolio_id'];
        var_dump($data);
        echo $data;
        exit();
    }

var_dump($ data)给了我这样的东西

array
 'portfolio' => string 'Umair Portfolio 1' (length=17)

Array

我如何获得身份证?

有什么建议吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

您必须将属性ID更改为值

<option value={{ portfolio.id }}>{{ portfolio.portfolioName }}</option>