Php CodeIgniter URL路由工作不正常
通常CodeIgniter URL格式是Php CodeIgniter URL路由工作不正常,php,codeigniter,Php,Codeigniter,通常CodeIgniter URL格式是domain/controllerName/functionName/:id,但我希望它像domain/product name/product detail page一样。我在routes.php中也做了更改,但它给了我404页试试这个 application/config/routes.php $route['product-detail/(:any)'] = 'Controller/function/$1'; 在浏览器上点击productdeta
domain/controllerName/functionName/:id
,但我希望它像domain/product name/product detail page
一样。我在routes.php中也做了更改,但它给了我404页
试试这个
application/config/routes.php
$route['product-detail/(:any)'] = 'Controller/function/$1';
在浏览器上点击productdetail/
将调用Controller/function/$1
此处$1将代表产品id
public function product_detail($product_id)
请参阅codeigniter.com/user_guide/general/routing.html查看此处,并检查您的类和文件名,确保只有第一个字母是大写。示例:Welcome.php
和class Welcome extensed CI_Controller{}
我只参考了这个链接,并尝试了这个$route['index/viewAllCourses']='coursess';在我的routes.php文件中,但当我加载我的domain/index/viewAllCourses页面时,它会显示404页面。类名称都很好。您需要从数据库动态路由吗?还是静态路线?@MohsenShakibafar动态。我不想要控制器名或方法名,我只想要产品名显示为这个域名/产品名。我尝试了你建议的方式$路由['index/(:any)]='index';其中index是我的控制器名称。因此,当我用index/blah-blah点击任何URL时,它应该将我重定向到index/page,但什么也没有发生。好的,设置如下路由$route['product-detail/(:any)]='index/product\u detail/$1'
,在索引控制器中创建一个函数,如下所示公共函数product\u detail($product\u id)
。希望这能对你有所帮助。