你好我试图搞定symfony2框架的问题。我正在尝试渲染表单,当用户提交时,在新渲染的树枝中打印它们的响应。
我目前正在使用类Symfony \ Bundle的ContextErrorException对象\ FrameworkBundle \ Templating \ TemplateReference无法转换为int。
我也试过清理我的缓存。
我的控制器
<?php
namespace Acme\DemoBundle\Controller;
use Acme\DemoBundle\Entity\Product;
use Acme\DemoBundle\Entity\Task;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
类DefaultController扩展Controller {
/**
* @Route("/task/create", name="taskcreate")
*/
public function newAction(Request $request)
{
// create a task and give it some dummy data for this example
$task = new Task();
$task->setTask('Write a blog post');
$task->setFname('james');
$task->setLname('gibbs');
$form = $this->createFormBuilder($task)
->add('task', 'text')
->add('fname', 'text')
->add('lname', 'text')
->getForm();
if ($request->getMethod() == 'POST') {
$form->bind($request);
$data = $form->getData();
return $this->render('AcmeDemoBundle:Default:show.html.twig',
array(
'task' => $task->getTask(),
'fname' => $task->getFname(),
'lname' => $task->getLname(),
)
);
}
else
{
return $this->render('AcmeDemoBundle:Default:index.html.twig', array(
'form' => $form->createView(),
));
}
}
}
我的观点我想要显示重定向代码 {%extends&#39; :: base.html.twig&#39; %}
{% block body %}
<h1>it worked</h1>
{{Task}}
{{Fname}}
{{Lname}}
{% endblock %}
<?php
// src / Acme / TaskBundle / Entity / Task.php 命名空间Acme \ DemoBundle \ Entity;
我的php类任务 课程任务 { protected $ task;
protected $fname;
protected $lname;
public function getTask()
{
return $this->task;
}
public function setTask($task)
{
$this->task = $task;
}
public function getFname()
{
return $this->fname;
}
public function setFname($fname)
{
$this->fname = $fname;
}
public function getLname()
{
return $this->lname;
}
public function setLname($lname)
{
$this->lname = $lname;
}
}