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

Micro routing for a directory and any contents

I want to direct /abc to Phalcon Micro instead of the full Phalcon. I start with the following code. The problem is the $app->map("/abc", in the micro code.

$uri_parts = explode('/', $_SERVER['REQUEST_URI']); if (count($uri_parts) > 1 and $uri_parts[0] == '' and $uri_parts[1] == 'css') { require APP_PATH . 'app/index-micro.php'; }

I need a map route string to include /abc, /abc/, /abc/something.html, and exclude /abcx. There are some posts for handling /abc/{params}. As a way to get things started, I created several maps pointing to the same code. I could not make map handle /abc/.



9.7k
edited Jun '17

I found $app->map('/abc', 'process'); handles /abc and /abc/. I added code to check the depth of the request then use one of the following maps.

$app->map('/abc', 'process')

$app->map('/abc/{file}', function($file) { abc($file); });

$app->map('/abc/{sub}/{file}', function($sub, $file) { abc($sub . '/' . $file); });

edited Jun '17

Yea as i remember this is a problem with micro that it automatically removes backslashes because someone wrote it like this for some reason. This is why $app->map("/abc" handles both /abc/ and /abc



9.7k

Do you know how to make it handle /abc/* in the same map?



145.0k
Accepted
answer

It's not possible, just add other map.



9.7k

Ok, I am using another map.



9.7k

Interesting performance change. I replaced $app->map(....) and $app->handle() with plain code. Saved 0.002 seconds per request.

I am testing with a PC equivalent to a low end VPS. With $app->map(....) and $app->handle(), that part of the request uses between 0.008037 seconds and 0.008871 seconds. Without the $app, the time ranges from 0.006039 to 0.006603 seconds.

edited Jul '17

Kind of obvious, phalcon wont be faster than plain php code :D Especially not-oop php code.

Phalcon isn't some magic tool which boost php performance.



9.7k

For complicated routing, a whole Web site, Phalcon should save time. My project has simple routing at this stage. Most of my projects have simple routing. The complicated routing cases were from conversions of old sites where twenty developers each implemented their own directory structure. :-(