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

How can i use phalcon with mvc without inside routing system?

Hello.

Can any help me.

I just can't understant how i can use phalcon with mvc without build in routings? I need to use apache for rewrite urls and in phalcon use some params like "?control=somecontrol&action=someaction".

Best Regards.

Can you post your apache config here? I'm not 100% sure why you do application routing in your server configuration. Regardless, phalcon uses its routing system for sending requests to the appropriate module/namespace/controller/action in your app code. You will at some level need to use the phalcon routing engine to forward any request to the action method.

If you only have the ability to modify $_GET parameters (like ?control=somecontrol&action=someaction) then what you could possibly do is set up 1 default route to an IndexController that has all of the forward logic built in to it:

// all requests would go to this controller method
public function indexAction()
{
    $controller = $this->request->getQuery( 'control' );
    $action = $this->request->getQuery( 'action' );

    $this->dispatcher->forward(
        array(
            "controller" => $controller,
            "action" => $action
        ));
}

Hello Mike.

Thank you for your reply. I like your decision but i think i need more rooted possibility. Did you know can i use phalcon mvc without routing system and how?

This is example of my apache rewrite config:

RewriteRule ^/catalog/(.+)/(.+)/(\d+)/((\d+).html)$ /index.php?controller=catalog&action=year&make[]=$1&model[]=$2&year[]=$3&year[]=$3&page=$4 [NC,L,QSA] RewriteRule ^/catalog/(.+)/(.+)/((\d+).html)$ /index.php?controller=catalog&action=model&make[]=$1&model[]=$2&start=$3 [NC,L,QSA] RewriteRule ^/catalog/(.+)/((\d+).html)*$ /index.php?controller=catalog&action=make&make[]=$1&start=$2 [NC,L,QSA]

How i understand in phalcon mvc with routing all url path send in "_url" variable. But i need to send to app variables like "controller", "action" etc. This is just for back-compability with my current app architecture.



98.9k
Accepted
answer

You can replace the router by a custom router. It must be a class implementing Phalcon\Mvc\RouterInterface:

<?php

class MyRouter implements \Phalcon\Mvc\RouterInterface
{
    public function getControllerName()
    {
        return $_GET['controller'];
    }

    public function getActionName()
    {
        return $_GET['action'];
    }

        //more methods
}

Then you can use this class as router service:

$di['router'] = function()
{
    return new MyRouter();
};

just AWESOME phalcon is all i need!!!