【问题标题】:Route redirecting to wrong view路由重定向到错误的视图
【发布时间】:2017-03-15 16:24:39
【问题描述】:

我很困惑,无法弄清楚我哪里出错了。

我用一些方法为 /barcodes 和一个barcodeController 创建了路由。

当我点击 /barcode 路由时,它似乎进入了一个已设置的 404 页面,而不是返回一些文本。

有人能看出为什么会这样吗? 从逻辑上讲,这应该可行吗?

这里是代码......

routes.php -

Route::group(array('prefix' => 'barcodes'), function()
{
   Route::any('/', array('as' => 'barcodes.home', 'uses' => 'BarcodesController@home'));
   Route::any('/{page?}/{seg1?}/{seg2?}', array('uses' => 'BarcodesController@index'));
}); 

条形码控制器.php

class BarcodesController extends FrontEndController {

public function __construct()
{
  Parent::__construct();
  new ContentController;
}


public function index($page = null, $sub_page = null, $id = null)
{
  $keepPage = '/'.$page;
  $page = str_replace('-', '_', $page);
  $sub_page = str_replace('-', '_', $sub_page);
  if (method_exists($this, $page))
{
  return $this->$page($sub_page, $id);
}
else if (SitesPages::pageExists($keepPage))
{
  return View::make('sites.default.page');
}
else
{
  return View::make('errors.404');
}
}


public function home()
{
   if (\Reuest::segment(3) == "")
    {
      return "barcodes";
    }
     else{
       return "sitesbarcodes";
    }
 }

 public function howto()
 {
     return View::make('sites.barcodes.howto');
  }
}

【问题讨论】:

  • 1.您能确认它显示的是您的自定义 404 页面还是默认页面?
  • 点击路由/barcodes时显示自定义404

标签: php laravel laravel-4 controller routes


【解决方案1】:

您的路线 '/barcode' 似乎正在进入 /{page?}/{seg1?} 路线,但它无法根据您的路线定义找到方法 'barcodes'

【讨论】:

  • 那你有什么建议?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 2021-08-22
  • 2020-02-12
  • 2017-12-06
  • 1970-01-01
相关资源
最近更新 更多