gabordemooij / straight

The Straight Framework for PHP
Other
16 stars 3 forks source link

Optional sections in slugs? #2

Closed eyan closed 5 years ago

eyan commented 5 years ago

Say I have:

GET /article/123
__url_get_article( 123 );

and I just access /article/. Straight gives me an error.

Any way we can leave out 123 and still let __url_get_article() handle the request?

gabordemooij commented 5 years ago

Hi

Sorry for my late response, I must have missed this one.

Strange though, I cant seem to reproduce this error:

function __do_get_article($a) { die("Artikel $a"); }

/ Handle requests / if (!fmap( [ '/web/straight/public_html'=>''], '__do' )) { //working from subfolder here but should make no difference,... / No request handler has been found... / http_response_code(404); die('wut?'); }

../article/9 --> Artikel 9 ../article/ --> Artikel ../article --> Artikel

??

eyan commented 5 years ago

Hi,

Thank you for getting back to me.

When I access /sample or /sample/ defined as function __do_get_sample($x):

Fatal error: Uncaught ArgumentCountError: Too few arguments to function __do_get_sample(), 0 passed in D:\binxampp\htdocs\xxx\src\lib\Straight\straight.php on line 94 and exactly 1 expected in D:\binxampp\htdocs\xxx\src\app\controller\sample.php:93

Not a big problem, really. Was just wondering if there's a simple solution.

Closing this and will dig some more. Problem might be on my side.

Again, thank you.

gabordemooij commented 5 years ago

What happens if you use:

function __do_get_sample($x = null){:

?

eyan commented 5 years ago

No error! 💃 Woohoo!

Thank you! Sorry I didn't think of that myself.

gabordemooij commented 5 years ago

you're welcome!