我想为我存储在数据库中的产品创建更多 SEO 友好的 URL。
如何从 URL 获取 ProductName?
例如:
http://domain.com/ProductName
Run Code Online (Sandbox Code Playgroud)
其中 ProductName 不是 Controller。我需要从控制器验证 ProductName 并显示它。
我个人会创建一个名为 products 的控制器,它接受一个参数来从数据库中查找产品:
class Products extends CI_Controller
{
public function index($productname)
{
$data['product'] = $this->db->get_where('products', array('urlname' => $product))->row_array();
// other functionality here and view loading
}
}
Run Code Online (Sandbox Code Playgroud)
然后为这个场景添加路由(config/routes.php):
$route['other/routes/first'] = "their/correct/controller/$1";
$route['/(:any)'] = "/products/index/$1";
Run Code Online (Sandbox Code Playgroud)
自从我使用 CI 已经有一段时间了,但这应该可以帮助您指出我希望的正确方向。
| 归档时间: |
|
| 查看次数: |
1088 次 |
| 最近记录: |