Good day, community! I want to write for myself a good router, I looked at different options: with routes, without routes, control only through URI, etc. and etc. I have a little PHP programming experience, so after reading here, there I decided to write here. Solve this question, so to speak, in living answers. The bottom line: I want my routes to be like this
return array( "index"=>array("controller"=>"index", "method"=>"index","args"=>array("number"=>"2", "type"=>"family")), "notes/([-_a-z0-9]+)"=>array("controller"=>"index", "method"=>"index", "args"=>array("param"=>"2", "mouse"=>"grey")), "note/([/d])"=>array("controller"=>"index", "method"=>"index", "args"=>array("number"=>"2", "type"=>"family")), ); In other words, I want to take a string from the URL, and, comparing it with the routes, get the controller, method, arguments. (As always shorter).
By the principle of this:
return array( 'about' => 'page/show/about', 'page/([-_a-z0-9]+)' => 'page/show/$1', 'users/([-_a-z0-9]+)' => 'users/show/$1', ); Now questions:
I do not quite understand the principle of key matching, which uses a regular expression with a value. Namely this:
Did I understand correctly that the regular expression ([-_a-z0-9] +) and $ 1 are the same? How is it read? Like, $ 1 is assigned the value of a regular expression in an array key?'page/([-_a-z0-9]+)' => 'page/show/$1'Do you think that such a detailed splitting of the route into controller-method-arguments in the route array itself will in some way make it difficult to work in the future? Is it worth doing this? Maybe it's better to receive a string as usual, and only then, in the function itself, break it and continue to work with it?
Yes, I looked at different implementations of routers, in frameworks and just solutions. I would not want the extra manipulations that are usually offered in frameworks. As for bicycles: I am not going to invent something new, I just want to make a convenient solution for me to work and so that I fully understand what is being done there. Probably a trashed topic, but I think everyone has some preferences in finding some kind of solution. Maybe your decision will be the point of this question.
Thanks for answers.