Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 对非对象(实际上是对象)调用成员函数xx()_Symfony - Fatal编程技术网

Symfony 对非对象(实际上是对象)调用成员函数xx()

Symfony 对非对象(实际上是对象)调用成员函数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

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\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();
}