从CakePHP 1.2到1.3的升级打破了我的路线,尽管它们应该是1.3兼容的

时间:2011-09-02 09:18:06

标签: php cakephp routes cakephp-1.3

我使用“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 * 不起作用 *。应该使用控制器“产品”和默认操作“索引”匹配#6但它认为“lv”是控制器(忽略:lang param)
  • / 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}")
    );

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

对于默认的root,我猜你想要'/''/<param>'

'/:lang/'期待lang有什么东西 - 它不是可选的,afaik。请改为'/:lang'