Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.

$uriparts = explode('/', $SERVER['REQUESTURI']); if (count($uriparts) > 1 and $uriparts[0] == '' and $uriparts[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/.



2.9k
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



2.9k

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



99.6k
Accepted
answer

It's not possible, just add other map.



2.9k

Ok, I am using another map.



2.9k

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.



2.9k

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. :-(