ThinkPHP、ZF2、Yaf、Laravel框架路由大比拼(2)


<a href="https://www.jb51.net/tp/user">/tp/user<a/><br />
<a href="https://www.jb51.net/tp/user/jing">/tp/user/jing<a/><br />
<a href="https://www.jb51.net/tp/user/jing/blog">/tp/user/jing/blog<a/><br />
<a href="https://www.jb51.net/tp/user/jing/blog/1">/tp/user/jing/blog/1<a/><br />

访问上面4个链接,依次返回:

我是用户列表^_^
欢迎你,jing
这是jing的博客列表
jing的这篇博客的id为1
下面其他框架,也同样输出以上内容。

Zend Framework 2

使用ZF2骨架程序创建一个ZF2项目:

composer create-project --stability="dev" zendframework/skeleton-application zf2

修改默认模块Application的配置文件zf2\module\Application\config\module.config.php:

<?php /** * Zend Framework () * * @link for the canonical source repository * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. () * @license New BSD License */ return array( 'router' => array( 'routes' => array( 'home' => array( 'type' => 'Zend\Mvc\Router\Http\Literal', 'options' => array( 'route' => '/url', 'defaults' => array( 'controller' => 'Application\Controller\User', 'action' => 'url', ), ), ), // The following is a route to simplify getting started creating // new controllers and actions without needing to create a new // module. Simply drop new controllers in, and you can access them // using the path /application/:controller/:action 'application' => array( 'type' => 'Literal', 'options' => array( 'route' => '/application', 'defaults' => array( '__NAMESPACE__' => 'Application\Controller', 'controller' => 'Index', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'default' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'constraints' => array( 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( ), ), ), ), ), 'user_list' => array( 'type' => 'Segment', 'options' => array( 'route' => '/user[/]', 'defaults' => array( '__NAMESPACE__' => 'Application\Controller', 'controller' => 'User', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'user' => array( 'type' => 'Segment', 'options' => array( 'route' => '[:name][/]', 'constraints' => array( 'name' => '[a-zA-Z0-9_-]+', ), 'defaults' => array( 'action' => 'show', ), ), 'may_terminate' => true, 'child_routes' => array( 'blog_list' => array( 'type' => 'Segment', 'options' => array( 'route' => 'blog[/]', 'constraints' => array( ), 'defaults' => array( 'controller' => 'Blog', 'action' => 'index', ) ), 'may_terminate' => true, 'child_routes' => array( 'blog' => array( 'type' => 'Segment', 'options' => array( 'route' => '[:blog_id]', 'constraints' => array( 'blog_id' => '[0-9]+', ), 'defaults' => array( 'action' => 'show', ) ), 'may_terminate' => true, ), ), ), ), ), ), ), ), ), 'service_manager' => array( 'abstract_factories' => array( 'Zend\Cache\Service\StorageCacheAbstractServiceFactory', 'Zend\Log\LoggerAbstractServiceFactory', ), 'aliases' => array( 'translator' => 'MvcTranslator', ), ), 'translator' => array( 'locale' => 'en_US', 'translation_file_patterns' => array( array( 'type' => 'gettext', 'base_dir' => __DIR__ . '/../language', 'pattern' => '%s.mo', ), ), ), 'controllers' => array( 'invokables' => array( 'Application\Controller\Index' => 'Application\Controller\IndexController', 'Application\Controller\User' => 'Application\Controller\UserController', 'Application\Controller\Blog' => 'Application\Controller\BlogController', ), ), 'view_manager' => array( 'display_not_found_reason' => true, 'display_exceptions' => true, 'doctype' => 'HTML5', 'not_found_template' => 'error/404', 'exception_template' => 'error/index', 'template_map' => array( 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', 'application/index/index' => __DIR__ . '/../view/application/index/index.phtml', 'error/404' => __DIR__ . '/../view/error/404.phtml', 'error/index' => __DIR__ . '/../view/error/index.phtml', ), 'template_path_stack' => array( __DIR__ . '/../view', ), ), // Placeholder for console routes 'console' => array( 'router' => array( 'routes' => array( ), ), ), ); ?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/bc5f527729b633e686f94b682c004945.html