【问题标题】:laravel visit error in route in the example in getting started with laravel 4laravel 4 入门示例中路径中的 laravel 访问错误
【发布时间】:2014-09-15 03:20:40
【问题描述】:

我的源代码在 https://github.com/xsmyqf/startlaravel.git 在分支 userauth 中。

我有一个问题,当我访问 localhost/startlaravel/public/cats/create 时,它​​会打印页面未找到! 但是最令人困惑的地方是该页面究竟存在于文件夹中,并且在 routes 文件中有一个 cat/create 路由!

可以在分支 master 中访问相同的路由!除了添加身份验证之外,我什么也没做。

感谢您的任何想法!

我已经搜索过谷歌,但我真的不知道为什么我不能访问现有的路线!

【问题讨论】:

    标签: laravel-4 laravel-routing


    【解决方案1】:

    在“#Laravel IRC 频道”中,一个叫 trq 的人帮我解决了问题:

    <trq> The reason is routes are processed in order. The cats/{cat} route matched but was unable to find anything by that id.
    <xxs> cats/create can match /cats/{cat}
    <xxs> cats/{cat} have )->where('id', '[0-9]+');
    <trq> /cats/{cat} matches any string that looks like /cats/whateverthehellisthis
    <xxs> cats/{cat} have )->where('id', '[0-9]+');
    <xxs> only allow number
    <trq> your not using id anywhere
    <trq> that should likey be ->with('cat', '[0-9]+');
    <xxs> oh!smart eyes
    <xxs> I got it
    <xxs> thanks very much
    

    【讨论】:

    • 注意它是 ->where('cat', '[0-9]+');而不是 ->with!
    【解决方案2】:

    假设您尝试通过转到

    来查看它
    http://localhost/startlaravel/public/cats/create
    

    在您的浏览器中(或类似的东西)。

    您不会想访问startlaravel/public/cats/create,而是想访问cats/create。所以,

    http://localhost/cats/create
    

    原因是,public是根目录,不是startlaravel。

    【讨论】:

    • 你至少需要尝试进入项目文件夹
    • 这取决于您如何设置您的网络服务器。我的根目录直接指向 laravel 的公共目录。
    【解决方案3】:

    你的路径是 startlaravel/cats/create

    如果你的安装目录是 startlaravel 如果你在 /var/www/ 中有 laravel 那么你应该访问

    http://127.0.0.1/cats/create
    

    http://127.0.0.1/cats
    

    【讨论】:

      猜你喜欢
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多