php - URL Routing to single Index File -
i have website: http://chanl.co.uk/ blog. each post has it's own permalink goes specific url on page. in projects i've worked on in past, these links routed different index files in seperate folders use same template each post , select data dependent on it's permalink. im looking way have single file posts route when accessed. link how wordpress use "single-post" template every post on website.
i'm little stumped how go form of dynamic routing almost, , don't know start. route have auto-generated every post in database or there more practical way solve issue.
awful diagram:
(my train of thought) chanl - post1 / index.php post2 / index.php (optimal solution) chanl - posts.php (all posts directed here)
you want @ how simple php framework works, every request passed index.php file in root directory , routes defined urls using (guess what!) router...
some things encounter are.
1 - front controller patter 2 - mvc pattern 3 - controllers , methods (which known functions)
so typical url route this
www.example.com/shop/product/id=12
this translate to
www.example.com/controller/method/parameter
your controller php class, action function in class , parameter data want pass in (for example id).
all frameworks need routing , routing solutions range relatively simple complex.
i recommend video learn how basic famework functions , move on real framework such laravel. takes head banging (for me couple of weeks of pain) click.
https://www.youtube.com/watch?v=osctzgasimq&list=plfdtiltirhwgxvhxx09fxxdi-dqinchfd
Comments
Post a Comment