【发布时间】:2020-06-05 10:24:49
【问题描述】:
自从向模型函数添加分页后,我真的很难克服 CI4 中的 404 File Not Found 错误。我假设它仅与路由有关,因为它也在我的 subbrand_name 页面上抛出了相同的错误,该页面在其模型代码中不包含任何分页,并且在我将分页添加到 brand_name 页面之前工作正常.
我的路线文件:
$routes->get('shop/brands/(:segment)', 'Shop::brand_name/$1');
$routes->get('shop/brands/(:segment)/(:segment)', 'Shop::subbrand_name/$1/$2');
我的控制器:
public function brand_name($brand_name_slug)
{
$model = new ShopModel();
$data = [
'category_menu' => $model->category_menu(),
'brand_menu' => $model->brand_menu(),
'nav' => $model->nav(),
'subnav' => $model->subnav(),
'shop' => $model->brand_name($brand_name_slug),
'pager' => $model->pager
];
if (empty($data['shop']))
{
throw new \CodeIgniter\Exceptions\PageNotFoundException('Cannot find the news item: '. $slug);
}
echo view('templates/header', $data);
echo view('shop/view', $data);
echo view('templates/footer', $data);
}
我的模特:
public function brand_name($brand_name_slug)
{
return $this
->table('shop a')
->select()
->join('(SELECT sku, MIN(sale_price) AS sale_price FROM shop GROUP BY sku) AS b', 'a.sku = b.sku AND a.sale_price = b.sale_price')
->where('availability', 'in stock')
->where('a.sku !=', '')
->where('brand_name_slug', $brand_name_slug)
->groupBy('a.sku')
->orderBy('brand_name, subbrand_name, product, size, unit')
->paginate(15);
}
【问题讨论】:
-
您能否在获取 404 时添加您尝试访问的 url?
-
www.seixwebdev.co.uk/shop/brands/hugo-boss
-
另外,根本没有编辑 .htacess 文件。
标签: codeigniter pagination routes codeigniter-4