We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

routing does not work

I started learning about routing in Phalcon.

my directory structure is :

app

--- config

------ services.php

------ config.ini

------ loader.php

looks like INVO

and I try to add :

use Phalcon\Mvc\Router;

$router = new Router();

$router->add(
    "admin/:controller/:action/:params",
    array(
        "controller" => 1,
        "action" => 2,
        "params" => 3
    )
);

but, when I try to access : https://localhost/phalcon/admin/crud/index

it give me :

AdminController handler class cannot be loaded

this page was same like https://localhost/phalcon/crud/index



3.4k

Are you sure that you have the file AdminController.php in the right place?



3.5k

I didn't write AdminController.php, because I want https://localhost/phalcon/admin/crud/index to load the same controller in https://localhost/phalcon/crud/index



43.9k

Hi,

try with:

$router = new Router(false);



3.4k

Try this:

use Phalcon\Mvc\Router;

$router = new Router();

$router->add(
    "/admin/:controller/:action/:params", // add / at the begining
    array(
        "controller" => 1,
        "action" => 2,
        "params" => 3
    )
);

I didn't write AdminController.php, because I want https://localhost/phalcon/admin/crud/index to load the same controller in https://localhost/phalcon/crud/index



3.5k

@Tao Pan @le51 It give me result : Trying to call method handle on a non-object

Maybe I missed something in my codes...



43.9k

look wich function produce that error