类不存在symfony 4

时间:2019-03-09 11:40:26

标签: symfony

我正在使用symfony 4构建一个Crud应用程序。这是TodoController.php

<?php

namespace App\Controller;
 use App\Entity\Taskslist;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;

 class TodoController extends Controller{


/**

*   @Route("/",name="todo_list")


*/
public function listAction(){
   $todos=$this->getDoctrine()->getRepository('App:Taskslist')->findAll();
    return $this->render('todo/index.html.twig',array('todos' => $todos));

}
/**

*   @Route("/todo/create",name="todo_create")


*/

public function createAction(Request $request){

    return $this->render('todo/create.html.twig');

}
/**

*   @Route("/todo/edit/{id}",name="todo_edit")


*/
public function editAction($id,Request $request){

    return $this->render('todo/edit.html.twig');

}
/**

*   @Route("/todo/details/{id}",name="todo_details")


*/

public function detailsAction($id){

    return $this->render('todo/details.html.twig');

}

 }

这是实体:

<?php



use Doctrine\ORM\Mapping as ORM;

/**
 * Taskslist
 *
 * @ORM\Table(name="taskslist")
 * @ORM\Entity
 */
class Taskslist
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string", length=255, nullable=false)
     */
    private $description;

    /**
     * @var bool
     *
     * @ORM\Column(name="status", type="boolean", nullable=false)
     */
    private $status;






/**
*@param  int $id
*@return Taskslist
*/

  public function setId($id){
        this->id=$id;
        return $this;
    }
    /**
    *@return int 
    */
    public function getId(){
        return $this->id;
    }
/**
*@param  string $title
*@return Taskslist
*/

  public function setTitle($title){
        this->title=$title;
        return $this;
    }
/**
     * @return string
*/
    public function getTitle(){
        return $this->title;
    }


    /**
*@param  string $description
*@return Taskslist
*/

  public function setDesc($description){
        this->description=$description;
        return $this;
    }
/**
     * @return string
*/
    public function getDesc(){
        return $this->description;
    }

/**
*@param  bool $status
*@return Taskslist
*/

  public function setStatus($status){
        this->status=$status;
        return $this;
    }
/**
     * @return string
*/
    public function getStatus(){
        return $this->status;
    }

}

我尝试使用AppBundle代替App,但出现未知的别名错误。 实际上,我收到以下错误:类'App \ Entity \ Taskslist'不存在。 我遵循了许多教程,但是它们并没有帮助我 你能帮我么 ?预先感谢

1 个答案:

答案 0 :(得分:1)

您需要在实体类中使用名称空间。在php标记后的顶部添加此代码。与您的控制器相同:

namespace App\Entity;