简体   繁体   English

ini文件中的Zend框架路由链接

[英]Zend framework route chaining in ini file

I've got my routes configured as below: 我的路由配置如下:

routes.rooms.type = "Zend_Controller_Router_Route_Static"
routes.rooms.route = "/rooms"
routes.rooms.defaults.module = "rooms"
routes.rooms.defaults.controller = "index"
routes.rooms.defaults.action = "index"

routes.rooms.chains.room.type = "Zend_Controller_Router_Route_Regex"
routes.rooms.chains.room.route = "/(\d+)"
routes.rooms.chains.room.defaults.action = "room"
routes.rooms.chains.room.map.1 = "room_id"
routes.rooms.chains.room.reverse = "/%d"

;admin
routes.rooms.chains.admin.type = "Zend_Controller_Router_Route_Static"
routes.rooms.chains.admin.route = "/admin"
routes.rooms.chains.admin.defaults.controller = "admin"
routes.rooms.chains.admin.defaults.action = "index"

routes.rooms.chains.admin.chains.deletedrooms.type = "Zend_Controller_Router_Route_Regex"
routes.rooms.chains.admin.chains.deletedrooms.route = "/deletedRooms(?:/(\d+))?"
routes.rooms.chains.admin.chains.deletedrooms.defaults.action = "deletedrooms"
routes.rooms.chains.admin.chains.deletedrooms.map.1 = "page_id"
routes.rooms.chains.admin.chains.deletedrooms.defaults.1 = 1
routes.rooms.chains.admin.chains.deletedrooms.reverse = "/deletedRooms/%d"

All seems fine with the routes but when trying to construct a navigation menu using a route (current trying to use rooms-admin) the page shows nothing (blank white page, no error). 路线似乎一切正常,但是当尝试使用路线构造导航菜单时(当前尝试使用rooms-admin),该页面未显示任何内容(白页,无错误)。 If I remove the routes, then an error message stating the routes haven't been defined; 如果删除路由,则错误消息指出路由尚未定义; makes sense. 说得通。

If I comment out rooms-admin, a later route 'rooms-admin-deletedrooms' works fine.. so it seems rooms-admin is the problem. 如果我注释掉rooms-admin,则稍后的路由“ rooms-admin-deletedrooms”可以正常工作。

I've seen this: How do I write Routing Chains for a Subdomain in Zend Framework in a routing INI file? 我已经看到了: 如何在Zend Framework中的路由INI文件中为子域编写路由链? but I don't want to use the hostname part, I want my routes to be relative to the default routing system (making changes would take too long). 但我不想使用主机名部分,我希望我的路由相对于默认路由系统(进行更改将花费很长时间)。 Any ideas what could cause this error, are the routes defined correctly? 有什么想法可能导致此错误,路由定义正确吗?

On a side note, what is quicker to parse: ini or xml? 附带说明一下,什么是更快解析的:ini或xml? I'm guessing a php array is the quickest method out of all the options. 我猜想php数组是所有选项中最快的方法。

Not sure about the chaining problem you are having, but I do have a suggestion for the question about parsing your config. 不确定您遇到的链接问题,但是对于解析您的配置的问题,我确实有一个建议。 Cache the generated config in APC, since it is just an array. 将生成的配置缓存在APC中,因为它只是一个数组。

<?php
...
/** Zend_Application */
require_once 'Zend/Application.php';

// Use default application.ini config the first time
// then pull the php array from apc
$config_file = APPLICATION_PATH . '/configs/application.ini';
$config_cached = false;
if (apc_exists('application.ini')) {
    $config_file = apc_fetch('application.ini');
    $config_cached = true;
}

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    $config_file
);

// cache the application.ini config if this is staging or production
if (!$config_cached && ('development' != APPLICATION_ENV)) {
    apc_add('application.ini', $application->getOptions());
}

reference: http://www.hellotecho.com/cache-your-zend-framework-config-to-improve-performance 参考: http : //www.hellotecho.com/cache-your-zend-framework-config-to-improve-performance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM