gpt4 book ai didi

php - 如何在 Laravel 中设置默认 Controller ?

转载 作者:可可西里 更新时间:2023-11-01 12:28:35 24 4
gpt4 key购买 nike

我正在使用 Laravel PHP 框架并且想知道一些事情。默认的 application/routes.php 文件包含以下内容:

Route::get('/', function()
{
return View::make('home.index');
});

这只是输出 View ,但我如何从那里调用 Controller ?

我可以删除上面的整个路由并用 Route::controller('home') 替换它,它似乎在默认 URL 上使用家庭 Controller (即 example.com/)。但是像 Route::controller('article') 这样的任何其他 Controller 都不起作用,只能在 example.com/article 上使用。如何将文章 Controller 设置为默认值?

最佳答案

只需将 Controller 作为字符串传递,在类名和方法名之间使用@:

Route::get('/', 'article@index');

阅读the docs (滚动到标题为 Registering a route that points to a controller action 的示例)。

关于php - 如何在 Laravel 中设置默认 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14402967/

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