i create a controller pageController.php :
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class pageController {
public function index()
{
return new Response('<html><body>hello...</body></html>');
}
public function contactAction()
{
return new Response('<html><body>contact...</body></html>');
}
}
and here is the routes.yml
index:
path: /
controller: App\Controller\pageController::index
contact:
path: /contact
controller: App\Controller\pageController::contactAction
the index works fine, but the contact doesn't work!
Note: when I changed the path of index from "/" to "/index", it doesn't work anymore, it shows 404 not found
I don't want to use annotations until i want to fix this
contact:
path: /contact
controller: App\Controller\pageController::contact
Symfony will look for your contactAction you don't need to mention it in your YML
Ps: you don't call a route by a route name /index wont work but you call it by the path /
I don't know which version of symfony you are using, but if it is symfony 2.x then you should name your index method as indexAction (exactly like you have in contact).
routes.yml:
index:
path: /
controller: App\Controller\pageController::indexAction
controller:
public function indexAction()
{
return new Response('<html><body>hello...</body></html>');
}
You should also make sure that your routes.yml are properly loaded.
Related
Any ideas what can be wrong? PHP Storm says, that homepage is unused. On webside there is still symfony homepage so it doesnt work even on site.
routes.yaml
index:
path: /
controller: App\Controller\QuestionController::homepage
QuestionController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class QuestionController
{
public function homepage()
{
return new Response('What a bewitching controller we have conjured!');
}
}
Update:
/**
* #Route("/")
*/
also doesnt work work homepage()
in config/routes create file annotation.yaml
with such code:
controllers:
resource: ../../src/Controller/
type: annotation
that's all, enjoy :)
My Master controller located in "admin" folder. View image
here
namespace App\Controllers\admin;
use CodeIgniter\Controller;
class Master extends Controller
{
function __construct(){
helper('url');
}
public function index()
{
$data["content"]="view_home";
echo view('template/template', $data);
}
}
In my Routes.php i added this
$routes->get('admin/master','Master::index',['namespace','App\Controllers\admin']);
when i access the page in the browser i get this error
404 - File Not Found
Controller or its method is not found: {0}::{1}
What am i missing?
My silly mistake when setting up the route. I've put a "," instead of "=>". See the correct route below.
$routes->get('admin/master','Master::index',['namespace' => 'App\Controllers\admin']);
i'm very new to symfony and i'm stuck on an error.
I already searched for this over and over again but i didn't find any fix:
I installed the FOSUserBundle and i want to override layout.html.twig template to be my homepage of the website. I created a new bundle, made it a child of FOSUserBundle :
namespace Emag\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class UserBundle extends Bundle {
public function getParent(){
return 'FOSUserBundle';
}
}
I made a new file in the src/Emag/UserBundle/Resources/views/layout.html.twig and a new controller
class HomeController extends Controller {
public function homeAction()
{
return $this->render('UserBundle\layout.html.twig');
}
}
but i get this error:
Unable to find template "UserBundle\layout.html.twig".
here's also my routing.yml file:
emag_magazine_homepage:
path: /emag
defaults: { _controller: UserBundle:Home:home }
You should use the correct namespace; EMAGUserBundle not UserBundle inside your routing file and in the homeAction to get your code well organised,
and then you have to change :
return $this->render('EmagUserBundle\layout.html.twig');
to
return $this->render('EmagUserBundle:layout.html.twig');
I just followed the tutorial about single route on github for this bundle : https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/5-automatic-route-generation_single-restful-controller.md
But I got this error when I'm trying to load my home page:
"FileLoaderException: Cannot import resource "ADC\OgppBundle\Controller\OgppRestController" from "C:/wamp/www/Symfony/app/config\routing.yml" (Class could not be determined for Controller identified by "ADC\OgppBundle\Controller\OgppRestController".)
I know this is some basic stuff but I cannot make it work. Here is the code :
app/config/routing.yml
adc_rest:
resource: ADC\OgppBundle\Controller\OgppRestController
type: rest
ADC\OgppBundle\Controller\OgppRest.php
namespace ADC\OgppBundle\Controller;
use FOS\RestBundle\Controller\Annotations\View;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class OgppRestController extends Controller
{
public function getProfilesAction()
{
} // "get_profiles" [GET] /profile/all
public function getProfileAction($id)
{
} // "get_profile" [GET] /profile/{id}
}
EDIT : I tried to clear the cache in dev environment but when I do it I have the same issue.
Hope this helps
I don't know how FOSRestBundle works (I've never used it), but I think your controller file name is wrong, it should be OgppRestController.php, not OgppRest.php.
I'm working on a laravel package but my routes.php can't find my controller...
My package is called Blackbird\Bluebird and in my app.php settings file dashboard_uri is equal to 'admin'.
If I replace the Route::controller to Route::resource it al works find in my public directory, if I then switch to public/admin I get this error: Class Blackbird\Bluebird\Controllers\DashboardController does not exist. Note that it if I use Route::controller I get the error on the public directory aswell.
I already run composer dump-autoload...
What are my options?
routes.php:
$dashboardUrl = Config::get('bluebird::app.dashboard_url');
Route::controller($dashboardUrl, 'Blackbird\Bluebird\Controllers\DashboardController');
DashboardController.php:
<?php namespace Blackbird\Bluebird\Controllers;
class DashboardController extends BaseController {
public function getIndex()
{
return View::make('bluebird::dashboard'); // Opens View/Dashboard.blade.php
}
// Some more code...
}