把它放在routes.php中:
Route::controller('HomeController', '/');
这告诉你HomeController路由到网站的根目录。然后,从HomeController中,您可以从那里访问任何功能。只需确保在前面加上正确的动词。请记住,laravel遵循PSR-0和PSR-1标准,所以方法是基于camelCased。所以你会有类似的东西:
domain.com/aboutUs
在HomeController中:
<?php class HomeController extends BaseController { public function getAboutUs() { return View::make('home.aboutus'); } }
我使用routes.php和过滤器来做到这一点。我从漂亮的PongoCMS中复制了这个想法
https://github.com/redbaron76/PongoCMS-Laravel-cms-bundle/blob/master/routes.php
的 应用程序/ routes.php文件 强>
// automatically route all the items in the home controller Route::controller('home'); // this is my last route, so it is a catch all. filter it Route::get('(.*)', array('as' => 'layouts.locations', 'before' => 'checkWithHome', function() {})); Route::filter('checkWithHome', function() { // if the view isn't a route already, then see if it is a view on the // home controller. If not, then 404 $response = Controller::call('home@' . URI::segment(1)); if ( ! $response ) { //didn't find it return Response::error('404'); } else { return $response; } });
<击> 我看到的主要问题是过滤器基本上加载了所有成功的页面两次。我没有在文档中看到检测页面是否存在的方法。我可以写一个库来做。 击>
当然,对于这个最终版本,如果我找到了一些东西,我可以将其转储到页面上并停止处理路线。这样我只加载一次所有资源。
的 应用程序了/控制器/ home.php 强>
public function get_aboutUs() { $this->view_data['page_title'] = 'About Us'; $this->view_data['page_content'] = 'About Us'; $this->layout->nest('content', 'home.simplepage', $this->view_data); } public function get_featured_locations() { $this->view_data['page_title'] = 'Featured Locations'; $this->view_data['page_content'] = 'Featured properties shown here in a pretty row'; $this->layout->nest('content', 'home.simplepage', $this->view_data); } public function get_AboutYou() { //works when I return a view as use a layout return View::make('home.index'); }