1

我是 laravel 的新手,只是尝试了一些例子。这是:

laravel-master\app\controllers\account.php -

class AccountController extends BaseController
{
    public function action_index()
    {
        echo "This is the profile page.";
    }
    public function action_login()
    {
        echo "This is the login form.";
    }
    public function action_logout()
    {
        echo "This is the logout action.";
    }
}

然后我在 -laravel-master\app\routes.php

Route::controller('account');

所以我什么时候去主页

  • myproject/account/login 它应该显示“这是登录表单”。.

但它的表现

  • Missing argument 2 for Illuminate\Routing\Router::controller(), called in C:\Program Files\Zend\Apache2\htdocs\laravel-master\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 177 and defined.

不知道是什么问题。我在某个地方错了吗?

4

2 回答 2

7

将控制器文件的名称更改为:

laravel-master\app\controllers\AccountController.php

将路由定义更改为:

Route::controller('account', 'AccountController');

将控制器方法更改为:

class AccountController extends BaseController
{
    public function getIndex()
    {
        echo "This is the profile page.";
    }
    public function getLogin()
    {
        echo "This is the login form.";
    }
    public function getLogout()
    {
        echo "This is the logout action.";
    }
}
于 2013-08-05T07:14:18.133 回答
1

不是 Laravel 专家,但我认为您Route::controller缺少路由目的地的参数,您应该使用控制器类的全名。尝试

Route::controller('account', 'AccountController')

我也不确定action_s。如果我正确理解控制器上的文档,它们必须以 HTTP 动词为前缀,例如

public function getIndex()

代替

public function action_index()
于 2013-08-05T06:44:45.477 回答