doutang3077
2015-03-14 15:46
浏览 39
已采纳

使用Symfony和Doctrine创建小页面以显示表的内容

I am trying to create simple page to display content of the table (customer: id, first_name, last_name) with Symfony + doctrine. I created GS\OrderBundle\Entity\Customer with columns and getters/setters. Created route for it. I want to create a view , something like:

<table>
        {% for c in form %}
        {% set id = c.get('value') %}
        <tr>
            <td>{{ form_widget(c) }}</td>
            <td>{{ c[id].firstName }}</td>
            <td>{{ c[id].lastName }}</td>
        </tr>
    {% endfor %}
</table>

and Controller to pass the values from the customer table to this view. I am trying something like:

namespace GS\OrderBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use GS\OrderBundle\Entity\Customer;
use Doctrine\ORM\EntityManager;

class CustomerListController extends Controller
{
    public function listAction()
    {


        $repository = $this->getDoctrine()
            ->getRepository('GSOrderBundle:Customer');
        $customer = $repository->findAll();

        $form = $this->createFormBuilder($customer)->getForm();





        return $this->render(
            'customerTable.html.twig',
            array('form' => $form->createView())
        );

        return new Response($names);
    }
} 

On the symfony website I found only examples with setting data or outputing single row data. Could you please provide any simple example how to display content of the table in the view?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题