I'm trying to render a theme index file that I'm trying to import to pimcore to work with. I've put the theme folder in app/Resources/views.
I've added the following to my routing.yml file
index:
path: /static/dist/index.html
controller: AppBundle\Controller\indexController::index
below is my controller named indexController.php
<?php
namespace Appbundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class indexController extends FrontendController
{
/**
* #Route("/static/dist/index.html", name="homepage")
*/
public function index()
{
return $this->render('static/dist/index.html');
}
}
When I try to navigate to localhost/static/dist/index.html, I get the following error:
No engine is able to work with the template "static/dist/index.html".
Related
I'm new to Symfony and am trying to understand that controller response function. I just want to return a simple HTML file home.html, that at the moment just has a Hello World line in it.
How do I return the file as a response? As it stands with the code below it's just returning the string 'home.html'.
Many thanks.
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MainController
{
/**
* #Route("/")
*/
public function homepage()
{
return new Response('home.html');
}
}
Because you need to extend your controller with AbstractController and use the render method to generate the view from html.
class MainController extends AbstractController
{
/**
* #Route("/")
*/
public function homepage()
{
return $this->render('home.html');
}
}
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');
}
}
I'm facing a problem that I don't understand. I simply create a Controller with make:controller and everything works, but when I want to create a new method, my route annotation doesn't work (whereas the default one works normally). T
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* #Route("/default", name="default")
*/
public function index()
{
return $this->render('default/index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
/**
* #Route("/", name="home")
*/
public function home() {
return $this->render('default/home.html.twig');
}
}
The / route redirects me to the default page of Symfony and any other name for the route returns the No route found error.
Also, PHPStorm tells me that Import' Symfony\Component\Routing\Annotation\Route is never used when you can see that they are there...
How to solve this ? Thanks !
Check your config/routing.yaml
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 have written a series of working controllers within the directory /src/AppBundle/Controller/Admin, such as DoctorAdminController, PatientAdminController, etc. The top of these controllers look like so:
<?php
namespace AppBundle\Controller\Admin;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* #Route("/admin")
*/
class DoctorAdminController extends Controller
{
/**
* #Route("/doctor", name="admin_doctor_list")
*/
public function indexAction()
{
// stuff
}
}
I can navigate to each page exactly as expected:
http://example.com/admin/doctor
I would like to have a page sitting at http://example.com/admin, but for the life of me can't get get a working route. I have this as the controller for the index page:
<?php
namespace AppBundle\Controller\Admin;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* #Route("/admin")
*/
class DefaultAdminController extends Controller
{
/*
* #Route("/", name="default_admin")
*/
public function indexAction()
{
$this->render('admin/admin_base.html.twig');
}
}
I have my routing.yml file set to annotations:
app:
resource: "#AppBundle/Controller/"
type: annotation
When I try to access http://example.com/admin, I get a "No route found for GET /admin" error. Consistent with this, when I use ./bin/console debug:router there is no route listed for /admin, but I do see routes for all others (/admin/doctor, etc.)
What am I missing?
This is because you have your routing annotation before the class. You shouldn't do that, but instead put it in front of your actions only, like so:
<?php
namespace AppBundle\Controller\Admin;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultAdminController extends Controller
{
/*
* #Route("/admin", name="admin")
*/
public function indexAction()
{
$this->render('admin/admin_base.html.twig');
}
}
I also show this with the "name" using "admin" as well, so you can also specify "admin" in Twig and redirects using the same name; this is so it will make sense to you. Same thing for your DoctorAdminController, remove the routing annotation before the class.
That should fix the problems.