Annotations Router Parameters give PHP Missing Argument

I am trying to parse an argument from the route like this:

    /**
     * @Get("/lft/{id:[1-9]+}")
     */
        public function getByLftAction( $id )
        {
        }

But I keep geeting:<b>Warning</b>: Missing argument 1.

What am I doing wrong?



7.0k

See your Router service. You may set URISOURCESERVERREQUESTURI in router. Like this : $router->setUriSource(Router::URISOURCESERVERREQUESTURI); Or check your .htaccess file. I use REQUEST_URI is usually.



1.7k

Good point, I am now setting the router source explicitly but I still encounter the same problem.

Any other idea on what I can check?

nginx ```php location / { tryfiles $uri $uri/ @rewrite; } location @rewrite { rewrite ^(.*)$ /index.php?url=$1; } ```

service ```php $router = new Router(false); $router->setUriSource(Router::URISOURCEGET_URL); ```

controller ```php /** * @Get("/lft/{lft}") */ public function getByLftAction( $lft ) { var_dump($this->request->getQuery()); echo $lft; } ```

result ```php <b>Warning</b>: Missing argument 1 for .. array(1) { ["_url"]=> string(13) "/flight/lft/1" } ```



7.0k

No, no, no! Nowise any rewrite in nginx config. ```php location / { try_files $uri $uri/ /index.php; }

location ~* .php$ { tryfiles $uri =404; fastcgipass 127.0.0.1:9000; include /etc/nginx/fastcgiparams; fastcgisplitpathinfo ^(.+.php)(/.+)$; fastcgiindex index.php; fastcgiparam SCRIPTFILENAME /home/yourwebpublicdirectory/index.php; fastcgiparam SCRIPTNAME /index.php; fastcgiparam QUERYSTRING $uri$args; fastcgiparam REQUESTMETHOD $requestmethod; fastcgiparam CONTENTTYPE $contenttype; fastcgiparam CONTENTLENGTH $contentlength; fastcgiparam REQUESTBODY $requestbody; } ```



1.7k

Ok, I have tried with your config + adding:

  root /home/your_web_public_directory;

However, it didnt solve the problem. I got the first config from the documentation.



7.0k

This is config from real server: ```php server { listen 80; servername mysite.com; autoindex off; set $rootpath '/home/john/www/mysite/public'; root $root_path; index index.php;

location ~ assets/(css|js|img|video)/ { access_log off; expires 360d; }

location ~ favicon.ico$ { access_log off; expires 360d; }

location / { try_files $uri $uri/ /index.php; }

location ~* .php$ { tryfiles $uri =404; fastcgipass 127.0.0.1:9000; include /etc/nginx/fastcgiparams; fastcgisplitpathinfo ^(.+.php)(/.+)$; fastcgiindex index.php; fastcgiparam SCRIPTFILENAME /home/john/www/mysite/public/index.php; fastcgiparam SCRIPTNAME /index.php; fastcgiparam QUERYSTRING $uri$args; fastcgiparam REQUESTMETHOD $requestmethod; fastcgiparam CONTENTTYPE $contenttype; fastcgiparam CONTENTLENGTH $contentlength; fastcgiparam REQUESTBODY $request_body; }

} ## server config end ``` Thsi config work with ```php $router->setUriSource(Router::URISOURCESERVERREQUESTURI); ```



7.0k

P.S. Lighttpd work with Phalcon very nice + video streaming (HTML5).



1.7k

Thanks! I will use this configuration. However it still does not solve the problem :( I verified by running the php built in web server: ```php php -S 0.0.0.0:8000 -t . .htrouter.php ``` The route itself works because I have tested by changing the regex with [a-z] and [1-9]. I am beginning to think it is the passing of the parameter to the controller that doesnt work.



1.7k

Now it works! I didnt have a dispatcher service for the module I was routing.

I used your Phalconskeletonmulti to verify that it was possible to pass the parameters at all. It was :) After this I could compare the difference and noticed the dispatcher.

Thanks for your help and contribution!

EDIT: The real problem was the dispatch:beforeDispatchLoop event taken from http://docs.phalconphp.com/en/latest/reference/dispatching.html#preparing-parameters This code will set new parameters from the request and must be considered or removed when implementing the routes.



7.0k

I'm glad to help you.