In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the differences between ThinkPHP, ZF2, Yaf, and Laravel frame routing". In daily operation, I believe many people have doubts about the differences between ThinkPHP, ZF2, Yaf and Laravel frame routing. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the differences between ThinkPHP, ZF2, Yaf and Laravel frame routing?" Next, please follow the editor to study!
Demand:
/ user corresponding user list page
/ user/:user_id corresponds to the user's home page. For example, / user/AlloVince corresponds to the AlloVince user's home page.
/ user/:user_id/blog/ corresponds to the user's blog list page. For example, / user/AlloVince/blog lists the Blog written by AlloVince.
/ user/:user_id/blog/:blog_id a blog post corresponding to the user
The proposal is quoted from the original text:
'router' = > array (' routes' = > array ('user' = > array (' type' = > 'Segment',' options' = > array ('route' = >' / user [/]', 'defaults' = > array (' controller' = > 'UserController',' action' = > 'index',),' may_terminate' = > true) 'child_routes' = > array (' profile' = > array ('type' = >' Segment', 'options' = > array (' route' = >'[: id] [/]', 'constraints' = > array (' id' = >'[a-zA-Z0-9] -] +') Defaults' = > array ('action' = >' get'),), 'may_terminate' = > true,' child_routes' = > array ('blog' = > array (' type' = > 'Segment',' options' = > array ('route' = >' blog [/]') 'constraints' = > array (),' defaults' = > array ('action' = >' blog'), 'may_terminate' = > true 'child_routes' = > array (' post' = > array ('type' = >' Segment', 'options' = > array (' route' = >'[: post_id] [/]') 'constraints' = > array (' post_id' = >'[a-zA-Z0-94th -] +'), 'defaults' = > array (' action' = > 'post')),' may_terminate' = > true ), / / profile child_routes end), / / profile end), / / user child_routes end), / / user end),)
After reading this article, I intend to use the PHP framework I used to implement this routing requirement.
ThinkPHP
Create a new ThinkPHP project:
The copy code is as follows:
Composer create-project topthink/thinkphp tp-prefer-dist
The command line shows that I installed 3.2.2
Installing topthink/thinkphp (3.2.2)
I think the latest stable version of ThinkPHP's official website is 3.2.3.
I specially went to the packagist official website to check, and the stable version in the library is indeed 3.2.2.
I have to use 3.2.3. Why am I so obsessed with this? Because:
The routing function of 3.2is set for modules, so module names in URL cannot be routed, and routing definitions are usually placed in module configuration files. Version 3.2.3 begins to add support for global route definitions, which can be defined in the public configuration file of the project.
That is, the rewritten part of the route is the Controller and Action part, and the Moudle still exists.
I want / user, not home/user. (the default Module in ThinkPHP is Home,'DEFAULT_MODULE' = > 'Home', can be modified)
Of course, this problem can also be solved by modifying the .htaccess file. However, I decided to install 3.2.3.
Download the latest package on the ThinkPHP website and unzip it.
Use a browser to access the entry file of the project and let ThinkPHP automatically generate a default application module Home.
Modify the public configuration file tp\ Application\ Common\ Conf\ config.php:
Create the file tp\ Application\ Home\ Controller\ UserController.class.php:
Create the file tp\ Application\ Home\ Controller\ BlogController.class.php:
Visit: http://127.0.0.1/tp/url
Output:
The copy code is as follows:
/ tp/user
/ tp/user/jing
/ tp/user/jing/blog
/ tp/user/jing/blog/1
Visit the above four links and return in turn:
I am the user list ^ _ ^
Welcome, jing.
This is a list of jing's blogs
The id of this blog post of jing is 1.
The other frameworks below also output the above.
Zend Framework 2
Use the ZF2 skeleton program to create a ZF2 project:
Composer create-project-stability= "dev" zendframework/skeleton-application zf2
Modify the configuration file zf2\ module\ Application\ config\ module.config.php of the default module Application:
This file is included in the skeleton program, I only modified the router section and the controllers section. It would be too difficult for me to write such a long document. That's why ZF officially released a skeleton program.
Create the file zf2\ module\ Application\ src\ Application\ Controller\ UserController.php:
Create the file zf2\ module\ Application\ src\ Application\ Controller\ BlogController.php:
Zf2 does not support Action parameter binding. ThinkPHP not only supports binding, but also supports two binding methods: binding by variable name and binding by variable order.
Action in zf2 must return to the view unless exit (). If you know how to disable the view, please let me know.
Create the file zf2\ module\ Application\ view\ application\ user\ url.phtml:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.