Class Controller not found while loading - symfony

I was working on my first project with Symfony, I created my first controller. And this error appears.
problem image
I tried to
composer update
and I got the same problem!
The problem that appear when i update the composer
here is the code of TestController.php
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class TestController extends Controller {
/**
* #Route("/")
* #Method ({"GET"})
*/
public function index()
{
//return new Response('<html><body>Hello world</body></html>');
return $this->render('articles/index.html.twig');
}
}
index.html.twig file has only a <h1> test </h1> on it
What makes that problem appear? and how to fix it without deleting the project and creating it again!
thanks

Symfony\Bundle\FrameworkBundle\Controller\Controller has been deprecated since v4.2.0 and removed since v5.0.0, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class TestController extends AbstractController {
/**
* #Route("/", methods={"GET"})
*/
public function index()
{
//return new Response('<html><body>Hello world</body></html>');
return $this->render('articles/index.html.twig');
}
}

Related

Class "Symfony\Bundle\FrameworkBundle\Controller\Controller" not found while loading "App\Controller\StudentController"

Hi I'm fresher for symfony . when i execute the below code it will show error.i installed all the assets of symfony.help me to clear this..!
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class StudentController extends Controller
{
/**
* #Route("/")
* #Method({"GET"})
*/
public function index()
{
// return new Response(
// '<html><body><h1>HI,Welcome to Tamilnadu</h1></body></html>'
// );
return $this->render('student/index.html.twig');
}
}
I just put "hello" in (student/index.html.twig),and i commented the basic response function and want to run the return this function.
Try this:
/**
* #Route("/", name="index")
* #return Response
*/
public function index():Response{
return $this->render('student/index.html.twig');
}

Attempted to load class "Stripe" from namespace "Stripe". Did you forget a "use" statement for another namespace?

Impossible to load Stripe classe in my Symfony controller see :
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Stripe\Stripe;
class PointsController extends Controller
{
/**
*
* #Route("/points/buy", name="points_buy")
*/
public function buyAction(Request $request)
{
\Stripe\Stripe::setApiKey('sk_test_');
return $this->render('points/buy.html.twig', [
]);
}
}
Stripe added with composer in vendor directory
I tried Stripe::setApiKey('sk_test_') but same error ...
Any idea?
If you're importing Stripe\Stripe in your use statement then I don't think you need the fully qualified class name.
use Stripe\Stripe;
//// etc.
/**
*
* #Route("/points/buy", name="points_buy")
*/
public function buyAction(Request $request)
{
Stripe::setApiKey($secretKey);
}
Here's a Stripe service I created for one of my projects.

No route found for "GET /home"

I am using Symfony 3.4.3.
This is my routing in
app/config/routing.yml:
blog:
resource: "#BlogBundle/Controller/"
type: annotation
this is my controller from BlogBundle/Controller/DefaultController.php
<?php
namespace BlogBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
/**
* #Route("/home", name="home_route")
*/
class DefaultController extends Controller
{
public function indexAction()
{
return $this->render('BlogBundle:Default:index.html.twig');
}
}
And when I go to http://localhost:8000/home address I am getting this error: No route found for "GET /home"
So, what am I doing wrong here?
You add to set the route annotation on the action
<?php
namespace BlogBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
* #Route("/home", name="home_route")
*/
public function indexAction()
{
return $this->render('BlogBundle:Default:index.html.twig');
}
}
If you use annotation on the class, is to prefix all actions

Can't extend Doctrine's Repository

I'm trying to make a custom Doctrine's ORM Repository and extend it but I can't find a way to make it work. So far this is what i have:
The original Repository
//AppBundle\Repository\LocaleRepository.php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
use JMS\DiExtraBundle\Annotation as DI;
class LocaleRepository extends EntityRepository
{
protected myCustomFunction(){
}
}
The extended Repository
//OfficeBundle\Repository\OfficeRepository.php
namespace OfficeBundle\Repository;
use AppBundle\Repository\LocaleRepository;
class OfficeRepository extends LocaleRepository
{
//Empty class
}
My entiy:
namespace OfficeBundle\Entity;
// some calls to traits
use Doctrine\ORM\Mapping as ORM;
/**
* Office
*
* #ORM\Table(name="office__office")
* #ORM\Entity(repositoryClass="OfficeBundle\Repository\OfficeRepository")
*/
class Office implements TranslatableInterface{
//...
}
And Finally the call:
$em = $this->getDoctrine()->getManager();
$this->getEntityManager();
$office=$em->getRepository('OfficeBundle:Office')->myCustomeFunction($slug);
This trows the exception:
Undefined method 'myCustomFunction'. The method name must start with either findBy or findOneBy!
If I place myCustomeFunction inside the OfficeRepository it works fine but it brings down the purpose of extendind the repository. Also, the repository loaded by the controller is the correct one, vardumping the class shows: 'OfficeBundle\Repository\OfficeRepository'.
Finally I'm using KNP DoctrineBehaviors(translatable) on the office entity.
You must make your method public if you are going to use it outside the repository class.
class LocaleRepository extends EntityRepository
{
public function myCustomFunction()
{
....
}
}

Doctrine custom repository error

I've a brand new Symfony2 application and I'm 100% sure I've followed http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes to the letter. However I'm getting the following error;
Entity 'Core\MainBundle\Entity\LandingPromotions' has no field 'promotionType'. You can therefore not call 'findByPromotionType' on the entities' repository
I've no clue as to what I've missed. Code as follows;
LandingPromotions
<?php
namespace Core\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Core\MainBundle\Entity\LandingPromotions
*
* #ORM\Entity(repositoryClass="Core\MainBundle\Entity\PromotionRepository")
* #ORM\Table(name="landing_promotions")
*/
class LandingPromotions
{
//Normal entity stuff
}
PromotionRepository.php
namespace Core\MainBundle\Entity;
use Doctrine\ORM\EntityRepository;
class PromotionRepository extends EntityRepository
{
public function findByPromotionType($typeId)
{
}
}
Controller
namespace Core\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Core\MainBundle\Entity\Game;
use Core\MainBundle\Entity\LandingPromotions as LandingPromotions;
class GameController extends Controller
{
/**
* #Route("{_locale}/games/")
* #Template()
*/
public function indexAction($_locale)
{
$lp_repo = $this->getDoctrine()->getRepository('CoreMainBundle:LandingPromotions');
$lp_repo->findByPromotionType(2);
}
}
After much hair pulling and cursing I discovered that the entities are not using PHP annotations, but rather the XML versions. How this got mixed up I've no idea, but that'll be tomorrow's issue.

Resources