【问题标题】:An upgrade from CakePHP 1.2 to 1.3 broke my routes, although they should be 1.3 compatible从 CakePHP 1.2 到 1.3 的升级打破了我的路线,尽管它们应该与 1.3 兼容
【发布时间】:2011-11-09 00:49:53
【问题描述】:

我一直在使用“Migrating from CakePHP 1.2 to 1.3”指南将 CakePHP 从 1.2.10 升级到 1.3.11,我知道我必须确保我的路由与 1.3 兼容。

但是我的路线没有做任何不兼容的事情:

这不再受支持,因为中途贪婪星的行为 不规则且复杂的路由编译。这两个之外 边缘情况功能和上述更改路由器的行为与 它在 1.2 中实现

另一种极端情况是:

删除了使用完整正则表达式的第一个路径段。

我的路线表现如何:

  • 打开主页时,不起作用,但是在 1.2 上它成功匹配了路由 #1(由 Ivo 解决)
  • /lv/products *不起作用*。应该使用控制器“Products”和默认操作“index”匹配 #6,但它认为“lv”是控制器(忽略 :lang 参数)
  • /lv/products/index 有效!
  • /lv/products/view/productname 有效!

Cake 提供与此错误类似的错误(打开 /lv/products 时复制:

Missing Controller
Error: LvController could not be found.
Error: Create the class LvController below in file: app\controllers\lv_controller.php
<?php
class LvController extends AppController {

    var $name = 'Lv';
}
?>

我的路线:

    //Route #1: This route should have worked as a root route, because we have a default for :lang. But now i cannot open up the homepage if i don't define explicit "/" route
    Router::connect("/:lang/",
        array("controller" => "start", "lang" => "lv"),
        array("lang" => "[a-z]{2}")
    );

    //#2 This route seems to work ok.
    Router::connect("/admin/:lang/:controller/:action/*",
        array("lang" => "lv", "admin" => true),
        array("lang" => "[a-z]{2}")
    );

    // ==============================================================================

    //#3 Routes with static parts - works
    Router::connect("/:lang/info/*",
        array("controller" => "sections", "action" => "view", "lang" => "lv"),
        array("lang" => "[a-z]{2}")
    );

    //#4
    Router::connect("/:lang/news",
        array("controller" => "news", "action" => "listall", "lang" => "lv"),
        array("lang" => "[a-z]{2}")
    );

    //#5
    Router::connect("/:lang/employees",
        array("controller" => "employees", "action" => "index", "lang" => "lv"),
        array("lang" => "[a-z]{2}")
    );

    // ==============================================================================


    //#6 Catch all route. 
    Router::connect("/:lang/:controller/:action/*",
        array("lang" => "lv"),
        array("lang" => "[a-z]{2}")
    );

感谢您的帮助。

【问题讨论】:

    标签: php cakephp routes cakephp-1.3


    【解决方案1】:

    对于默认根,我猜你想要'/''/&lt;param&gt;'

    '/:lang/' 期望 lang 有一些东西 - 这不是可选的,afaik。请改用'/:lang'

    【讨论】:

    • 谢谢,默认路由现在可以使用了。但是 /lv/products 仍然不起作用。
    • 啊,我通过添加显式路由来修复它:Router::connect("/:lang/:controller", array("lang" =&gt; "lv"), array("lang" =&gt; "[a-z]{2}") );
    猜你喜欢
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 2015-07-05
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多