[英]Codedigniter dynamic uri segment
Lots of google search lots or research still unable to understand how do i create a uri in codigniter like i tried to create a dynamic link for my ads and listings for this i created a link in my view page like this 许多Google搜索批次或研究仍然无法理解我如何在codigniter中创建uri,就像我试图为我的广告和列表创建动态链接一样,我在这样的视图页面中也创建了链接
<li><a href="<?php echo base_url(). "listings/".$subcat->cat_name; ?>"><?php echo $subcat->cat_name ; ?></a></li>
and on the second page i want to call the listings by id i could have done by using simple get method but it will show the link as listings?cat=&subcat= and so on but I don't want this i want it to be like uri segment 在第二页上,我想通过id调用清单,我可以使用简单的get方法完成,但它将链接显示为清单?cat =&subcat =,依此类推,但我不希望这样做像uri段
to call the above statement i did this but it says 404 not found as the there is no named page as cat_name which would be the category name 调用上面的语句我做到了,但是它说找不到404,因为没有名为cat_name的命名页面将是类别名称
$cat = $this->uri->segment(3, 0);
if ($this->uri->segment(3) === FALSE)
{
echo $cat = 0;
}
else
{
echo $cat = $this->uri->segment(3);
}
and this is my controller listings.php 这是我的控制器listings.php
class listings extends CI_Controller {
public function index() {
$cat = "mylist";
$data['list'] = $cat;
$this->load->view('listings', $data);
}
}
Please can anyone help me out brothers 请任何人能帮助我兄弟
Add _remap to the controller. 将_remap添加到控制器。
public function _remap($method,$params = array()) {
if (method_exists($this, $method)) {
$this->$method($params);
} else {
$this->index($method, $params);
}
}
This declare any parameters after "listings/" as parameters for index function if the first parameters is not equal to a function name in your class. 如果第一个参数不等于您的类中的函数名称,则此方法将“ listings /”之后的所有参数声明为索引函数的参数。
Then you can have access to parameters in your index function like this. 然后,您可以像这样访问索引函数中的参数。
public function index($category = null, $params = null){
$subcategory = $params[0];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.