没有公共访问对象的属性?

时间:2019-01-25 13:54:31

标签: symfony

我正在尝试显示mysql数据库中的数据。我成功创建了一个实体,但是尽管有公共设置器和获取器,但是却以某种方式无法访问属性。

错误消息:

  

属性“ id”或方法“ id()”,“ getid()” /“ isid()”或“ __call()”都不存在,并且在类“ AppBundle \ Entity \ Todos”中没有公共访问权限“

我也尝试了differend命名,但似乎没有任何效果。我还可以转储对象,因此它必须存在,但是我无法获取其值

控制器功能:

public function listToDo(){
    $todos = $this->getDoctrine()->getRepository(Todos::class)->findAll();
    return $this->render('todo/index.html.twig', ['todos'=>$todos]);
}

Todos.php:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Todos
 *
 * @ORM\Table(name="todos")
 * @ORM\Entity
 */
class Todos 
{
    /**
     * @var integer
     *
     * @ORM\Column(name="ID", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="ToDo", type="text", length=65535, nullable=false)
     */
    private $todo;

    /**
     * Get id
     * 
     * @return integer
     */
    public function getid(){
        return $this->id;
    }

    /**
     * Get todo
     * 
     * @return string
     */
    public function gettodo(){
        return $this->todo;
    }

    public function setTodo($todo){
        $this->todo = $todo;
        return $this;
    }
}

index.html.twig:

...
{% for do in todos %}
    <tr>
        <td>{{ dump(do) }}</td>
        <td>{{ do.id }}</td>
        <td>
        </td>
    </tr>
    {% endfor %} 
...

有人想解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

尝试替换

"1\'; UPDATE foo SET text = LOAD_FILE(\'/something/something.txt\'); #- "

使用

public function getid(){
    return $this->id;
}

public function gettodo(){
    return $this->todo;
}

答案 1 :(得分:0)

getid()和gettodo()无效的cameCase格式。 您应该将方法重命名为 getId() getTodo()