I am trying to remove sensio/framework-extra-bundle from composer, however, when I do, I get the error above in my Controllers that have parameterized routes. Not finding the correct answer for a replacement?
Her is an example controller snippet.
namespace App\Controller;
use App\Entity\Ticket;
use App\Form\TicketType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/admin/ticket')]
class TicketController extends AbstractController
{
#[Route('/{id}', name: 'app_ticket_show', methods: ['GET'])]
public function show(Ticket $ticket): Response
{
return $this->render('ticket/show.html.twig', [
'ticket' => $ticket,
]);
}
}
Related
i have a problem with my Testproject, i tray to make Event, the function of this event is following, when the controller call the row with id 18 from the datebase, it will to call/dispach event, this event have to send email to a Email Adress.
the problem, i cannot call this event from my eventlistener, because i get the wrong:
Too few arguments to function App\customEvents\EmailEvent::SendEMail(), 0 passed in C:\xampp\htdocs\Authentication\src\EventListener\EmailListener.php on line 15 and exactly 1 expected
Controller:
namespace App\Controller;
use App\Entity\Posts;
use App\Repository\PostsRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class EventoController extends AbstractController
{
#[Route('/evento', name: 'app_evento')]
public function index(PostsRepository $Posts, EventDispatcherInterface $eventDispatcher): Response
{
$todo=$Posts->find(18);
$sendEmail=new \App\customEvents\EmailEvent;
$eventDispatcher->dispatch($sendEmail, \App\customEvents\EmailEvent::NAME);
return $this->render('evento/index.html.twig', [
'getdaten' => $todo,
]);
}
}
EmailListener
<?php
namespace App\EventListener;
use App\customEvents\EmailEvent;
use Symfony\Component\Mailer\MailerInterface;
class EmailListener
{
public function sendemailaktive( EmailEvent $MeinEmailEvent)
{
$MeinEmailEvent->SendEMail();
}
}
EmailEvent
<?php
namespace App\customEvents;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
class EmailEvent extends EventDispatcher
{
public const NAME = 'send.email';
public function SendEMail(MailerInterface $mailer)
{
$email = (new Email())
->from('hello#asdasd.com')
->to('spam#muhkas.com')
->subject('Email From Send!')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
$mailer->send($email);
}
}
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');
}
}
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.
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
Case mismatch between loaded and declared class names: "Symfony\Bundle\FrameWorkBundle\Controller\Controller" vs "Symfony\Bundle\FrameworkBundle\Controller\Controller".
In my controller i have this:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameWorkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class MainController extends Controller
{
public function homepageAction()
{
return $this->render('main/index.html.twig');
}
}
Maybe just fix what the error tells you? (sorry if that sounds harsh)
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
instead of
use Symfony\Bundle\FrameWorkBundle\Controller\Controller;