【问题标题】:How to: make my routes start working with Laravel 4?如何:让我的路线开始使用 Laravel 4?
【发布时间】:2013-06-15 03:02:33
【问题描述】:

我是 Laravel (v4.0.5) 的新手,根据网站 http://laravel.com/docs/routing 和我找到的其他书籍,让路线变得如此简单

Route::any('foo', function()
{
    return 'Hello World';
});

所以,我尝试在我的主机上

http//myhost/public/foo

(而且我必须使用 /public,因为如果我只直接进入我的主机,文件夹在哪里,我看到了框架的结构......有人知道这是为什么吗?)

但我得到找不到

我试过了

Route::any('user','UserController@index');

我已经像这样创建了我的控制器

<?php

class UsersController extends BaseController {

    public function showWelcome()
    {
        return View::make('users');
    }

    public function getIndex() 
    {
        return View::make('users');
    }
} 

并尝试使用/users,但没有...

知道我做错了什么吗?

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    试试看这里:

    http://myhost/public/index.php/foo
    

    如果你想使用它,你需要设置 URL 重写

    http://myhost/public/foo
    

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    【讨论】:

    • 谢谢!!它就是这样工作的!这是为什么?我怎样才能解决它不必编写 index.php ??
    • 因为你的第一个URL是在public目录中搜索foo目录,它不知道请求需要通过index.php文件处理。为了让它在不使用 index.php 的情况下工作,您需要在 Apache 中配置一些 URL 重写(通过 .htaccess 文件或 apache 配置文件)。见这里:stackoverflow.com/questions/12448912/…
    • 我用 apache 试过但没有结果,我会用 htaccess 试试
    【解决方案2】:

    您应该将服务器的 Web 根目录指向 public 文件夹。如果您使用的是 Apache,您可以在 httpd.conf 文件上更改此设置,查找 DocumentRoot 设置。示例:

    DocumentRoot "C:\Users\Raphael\Documents\GitHub\RaphStore\public"
    

    这很重要,因为它可以确保没有人可以访问您的项目文件,这是应该的。

    【讨论】:

    • 感谢您的回答,然后我将不得不创建规则,但是,您对路线有什么想法吗?
    猜你喜欢
    • 2014-12-19
    • 2018-08-01
    • 2014-01-10
    • 1970-01-01
    • 2013-05-01
    • 2015-07-08
    • 2013-12-17
    • 2013-02-04
    • 2013-12-03
    相关资源
    最近更新 更多