gpt4 book ai didi

laravel 4 使用通配符方法路由到 Controller

转载 作者:行者123 更新时间:2023-12-02 17:57:46 25 4
gpt4 key购买 nike

我正在使用最新的 Laravel4,目前正在测试路由和 Controller 。我想定义一个到 Controller (TestController) 的路由,该 Controller 负责可能的方法和所有其他 uri 段...

Route::controller('/test', 'TestController');

Controller :

<?php

class TestController extends BaseController {

public function index()
{
echo "index";
}

public function test()
{
echo "test";
}

public function missingMethod($parameters)
{
echo "missing method";
}

}

但这不起作用,总是得到:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

调用/test/test 或/test/index 时

缺少的方法也不起作用...?

最佳答案

您可以使用 RESTful Controller 方法来完成此操作。

// In routes.php
Route::controller('test', 'TestController');

然后在你的 Controller 中..../TestController.php

<?php

class TestController extends \BaseController {

public function getIndex()
{
return 'Hello World.';
}

public function getPage()
{
return "Hello World I'm another page";
}
}

关于laravel 4 使用通配符方法路由到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16757505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com