简体   繁体   中英

Class does not exist symfony 4

I am building a crud app using symfony 4. Here is the 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');

}

 }

And here is the entity:

<?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;
    }

}

I tried to use AppBundle instead of App but got an unknown alias error. Actually I am getting the following error: Class 'App\\Entity\\Taskslist' does not exist. I have followed many tutorials but they did not help me Can you please help me ? Thanks in advance

You need the namespace in your entity class. Add this at top after the php tag. Same way of you Controller:

namespace App\Entity;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM