1

I have This folder structure for my mvc project:

application
---admin
--------controller
--------model
--------view
--------language
---front
--------controller
------------------BlogController.php
--------model
--------view
--------language
core
public

I work With symfony router library and route my url like this:

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$routes = new RouteCollection();
$routes->add('blog_list', new Route('/blog', array(
    '_controller' => [application\front\controller\BlogController::class, 'index']
)));

return $routes;

BlogController.php is:

namespace application\front\controller;

class BlogController extends Controller
{
    /**
     * Construct this object by extending the basic Controller class
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
       echo 'fine';
    }
}

But In Action I can't see Any output. I think syfony can find my controller. Can I fix this problem ?!

1
  • Drop the ::class since you are spelling out the full qualiffied class name. Or, add a use statement then use [BlogController::class, Really seems like your code would have tossed an undefined constant message. Did you somehow manage to suppress all notices? Commented Jun 18, 2018 at 11:54

1 Answer 1

1

You didn't define which symfony version you are using. But checking from similar example on https://symfony.com/doc/current/routing/custom_route_loader.html for latest one (4.1), it looks like the controller value should be a string instead of an array (I haven't needed to use this kind of 'manual' route definition myself so I don't really know whether the constructor supports several different ways of defining the controller value - meaning that this is more of an educated guess what your issue could be :)).

$routes->add('blog_list', new Route('/blog', array(
    '_controller' => 'application\front\controller\BlogController::index'
)));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.