PHP Frameworking - Composer & Controllers (Part 3)



Since Jan 31, 2015 2 Posts

Great!

zooboole Since Jan 22, 2015 109 Posts

Note you must Escape the backslash in the Router dispatch() method like this:

$controller = "AppControllers\".$actionArr[0];

Also after doing all this I've noticed the the $view is no longer available in our routes file, what makes it impossible to add a route with a callable, but if you make this in the routes file it works it makes us declare the view variable twice:

$view = new PhpoceanCoreViewView(
    new PhpoceanCoreViewViewLoader(BASE_PATH.'/views/')
);

$router->add('/about-us',function() use ($view){

    $view->render('about.php');

});


$router->add('/','IndexController#index');

he same way you have to keep the $router = new PhpoceanCoreRouterRouter(); in bootstrap file in order to do $route->add() in our routes file.

In your composer.json, you don't need to add the ./ before the controllers folder.

To those who are not used to composer and psr-4 autoloading not that it's case sensitive


Since Apr 07, 2015 1 Posts

Hello, if I want to send anything via get and could do? for example, www.example.com/about?id=5

my router have $router->add('/about','AboutController#index');

I would have to change within the router.php function dispatch, it to work?

Since May 15, 2016 1 Posts

Hello, if I want to send anything via get and could do? for example, www.example.com/about?id=5

my router have $router->add('/about','AboutController#index');

I would have to change within the router.php function dispatch, it to work?

John Tec Since Jun 24, 2016 1 Posts

Hello, if I want to send anything via get and could do? for example,

www.example.com/about?id=5

my router have

$router->add('/about','AboutController#index');

I would have to change within the router.php function dispatch, it to work?

zooboole Since Jan 22, 2015 109 Posts

Definitely yes @John. You should be able to access it in your controller member with

$id = $_GET['id];

.