小智 24
我在那里创建了一个目录/ application/routes /并添加了文件.每个文件只是一组路由.然后在routes.php中添加了以下代码以包含它们:
// Dynamically include all files in the routes directory
foreach (new DirectoryIterator(__DIR__.DS.'routes') as $file)
{
if (!$file->isDot() && !$file->isDir() && $file->getFilename() != '.gitignore')
{
require_once __DIR__.DS.'routes'.DS.$file->getFilename();
}
}
Run Code Online (Sandbox Code Playgroud)
Mor*_*ews 21
即使采用了其他答案中提到的所有最佳实践,即:使用资源控制器,路由组等.
您可以通过旧时尚方式简单地"包含"路径文件.正如Chris G在本评论中提到的那样.
您可以创建简单的目录结构,并在route.php文件中包含路由文件.
../myroutes
--route-type-1.php
--route-type-2.php
Run Code Online (Sandbox Code Playgroud)
在route.php文件中
include('myroutes/route-type-1.php');
Run Code Online (Sandbox Code Playgroud)
它没有错.这是包中包含路由的方式.
http://laravel.com/docs/packages#package-routing
实际上溃败应该保持苗条.只需将代码移动到控制器并使用路径注册并重定向到它们.惯例是每个文件存储一个控制器,以便您的代码自动组织.
看看这个
// application/controllers/sample.php
class Sample_Controller extends Base_Controller
{
public function action_index()
{
echo "Wellcome to the root" //www.testapp.com/sample
}
public function action_edit()
{
echo "Some editing functions here." //www.testapp.com/sample/edit
}
public function action_whatsoever()
{
echo "Put here whatever you like." //www.testapp.com/sample/whatsoever
}
}
Run Code Online (Sandbox Code Playgroud)
控制器动作路径可以这样注册:
//application/routs.php
Route::controller('admin::home');
Run Code Online (Sandbox Code Playgroud)
非常直接和舒适.
更新:
您还可以自动为整个应用程序注册所有控制器:
Route::controller(Controller::detect());
Run Code Online (Sandbox Code Playgroud)
或者控制器包含所有动作:
Route::controller(Controller::detect('yourcontroller'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13274 次 |
| 最近记录: |