简体   繁体   English

在Codeigniter上替代uri片段?

[英]Alternative to uri segment on codeigniter?

Im getting the id from a form using 我从使用表单获取ID

  $id=$this->uri->segment(2) 

I need your help to replace that by something else generic without getting the id from the url im using pagination in several pages too & im using 我需要您的帮助,以其他通用方式替换该内容,而无需在多个页面中使用分页并通过im使用url im获取ID

$this->uri->segment() 

too .. 也..

PS:when i want to display a list o programs that belong to a category & when i want to display the list of programs of channel that belong to a category ,the segment change so i wont use the segment i wanna get the id dynamically .. PS:当我想显示属于某个类别的节目的列表时,以及当我想显示属于某个类别的频道的节目列表时,该段会发生变化,所以我不会使用该段,我想动态获取ID。 。

Best regards 最好的祝福

Don't know if this is what you are after, but you can send parameters in a standard codeigniter install with URI and catch them in the method params. 不知道这是您要追求的,但是您可以在带有URI的标准codeigniter安装中发送参数,并将其捕获到方法参数中。

class Welcome extends MY_Controller {

    public function index($a = NULL, $b = NULL, $c= NULL)
    {
        echo 'Testing params: <br> 
            Param1: ' . $a . '<br>Param2: ' . $b . '<br>Param3: ' . $c;
    }
}

Calling http://example.com/index.php/welcome/index/test1/test2/test3 will render 调用http://example.com/index.php/welcome/index/test1/test2/test3将呈现

Testing params: 
Param1: test1
Param2: test2
Param3: test3

Example

Going by this comment code: 通过此注释代码:

foreach $rows as $row .. .. id; foreach $ rows as $ row .. .. id; ?>" href="program/details_program/id; ?>“ href =” program / details_program / id; ?>"> program_title; ?> page detail.php $id = $this->uri->segment(2); $query = $this->db->get_where('programs', array('id' => $id)); ?>“> program_title;?>页面detail.php $ id = $ this-> uri-> segment(2); $ query = $ this-> db-> get_where('programs,array('id'=> $ id));

it looks like you have a program controller with a details_program method that you are linking to and this is where you want a different solution to uri->segment . 看来您有一个要链接到带有details_program方法的program控制器,这是您想要uri->segment的不同解决方案的地方。 If this is the case, something like this would work with a URL like http://example.com/program/program_details/123 : 如果是这种情况,则类似的方法可用于类似http://example.com/program/program_details/123的URL:

class Program extends CI_Controller{

    function program_details($id = NULL){
        $query = $this->db->get_where('programs', array('id' => $id));
    }

}

If this isn't what you want, please update the question with all of the relevant (properly formatted) code 如果这不是您想要的,请使用所有相关(正确格式)的代码更新问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM