Symfony 对非对象(实际上是对象)调用成员函数xx()
ValidateGatherType.phpSymfony 对非对象(实际上是对象)调用成员函数xx(),symfony,Symfony,ValidateGatherType.php namespace D2E\CoreBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\T
namespace D2E\CoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class ValidateGatherType extends AbstractType
{
private $gather;
public function __construct(Gather $gather)
{
$this->gather = $gather;
}
public function buildForm(FormBuilder $builder, array $options)
{
$gather_players = $gather->getGatherPlayers();
}
}
GatherController.php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class GatherController extends Controller
{
/**
* @Route("/teams/{id_team}/gather/{id_gather}")
* @Template()
*/
public function showAction(Team $team, Gather $gather)
{
new ValidateGatherType($gather);
}
执行此$gather->getGatherPlayers()时出错:
Soooooo,wtf(它被强制为聚集,但它不再是对象?)?我想我忘了用什么了,但我找不到什么了。
控制器代码是不同的,但由于这一行不起作用(即使我像我展示给你的那样使用它),我没有把其余的代码放进去
谢谢你的帮助
public function buildForm(FormBuilder $builder, array $options)
{
$gather_players = $gather->getGatherPlayers();
}
此处未定义局部变量$gather
。您可能指的是实例属性$this->gather
public function buildForm(FormBuilder $builder, array $options)
{
$gather_players = $gather->getGatherPlayers();
}