Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter中将uri段变量从一个函数传递到另一个函数_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php 在Codeigniter中将uri段变量从一个函数传递到另一个函数

Php 在Codeigniter中将uri段变量从一个函数传递到另一个函数,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,嗨,我在找人帮忙。我最近开始使用Codeigniter进行编码 我在同一个控制器中有两个功能。我需要从第一个函数到第二个函数的“uri段”。尝试谷歌,但没有成功 这是我的控制器: public item_page() { $id = $this->uri->segment(3); $this->load->view('view'); } public validation() { // Form Validation Goes Here

嗨,我在找人帮忙。我最近开始使用Codeigniter进行编码

我在同一个控制器中有两个功能。我需要从第一个函数到第二个函数的“uri段”。尝试谷歌,但没有成功

这是我的控制器:

public item_page() {
    $id = $this->uri->segment(3);
    $this->load->view('view');
}

public validation() {
    // Form Validation Goes Here
    if($this->form_validation->run() == FALSE) {
        $this->session->set_userdata('validation_errors', validation_errors());
        redirect('item-page/'.$id); // I need variable here
    } else {
    redirect('execute');
    }
}
private $page_id;

public item_page() {
    $id = $this->uri->segment(3);
    $this->page_id=$id;
    $this->load->view('view');
}

public validation() {
    // Form Validation Goes Here
    if($this->form_validation->run() == FALSE) {
        $this->session->set_userdata('validation_errors', validation_errors());
        redirect('item-page/'.$this->page_id); // I need variable here
    } else {
    redirect('execute');
    }
}

您可以在类(控制器)中添加某些属性

控制器:

public item_page() {
    $id = $this->uri->segment(3);
    $this->load->view('view');
}

public validation() {
    // Form Validation Goes Here
    if($this->form_validation->run() == FALSE) {
        $this->session->set_userdata('validation_errors', validation_errors());
        redirect('item-page/'.$id); // I need variable here
    } else {
    redirect('execute');
    }
}
private $page_id;

public item_page() {
    $id = $this->uri->segment(3);
    $this->page_id=$id;
    $this->load->view('view');
}

public validation() {
    // Form Validation Goes Here
    if($this->form_validation->run() == FALSE) {
        $this->session->set_userdata('validation_errors', validation_errors());
        redirect('item-page/'.$this->page_id); // I need variable here
    } else {
    redirect('execute');
    }
}
////// 方法2:

public item_page() {
        $id = $this->uri->segment(3);
        $this -> session -> set_userdata('id', $id);
        $this->load->view('view');
    }

    public validation() {
        // Form Validation Goes Here
        if($this->form_validation->run() == FALSE) {
            $this->session->set_userdata('validation_errors', validation_errors());
            redirect('item-page/'.$this -> session -> userdata("id")); // I need variable here
        } else {
        redirect('execute');
        }
    }

希望能有所帮助。

谢谢@Mohsen Shakibafar。。不幸的是,它不起作用。。当我通过
var\u dump($this->page\u id)在第二个函数中检查它时;死亡它说“空”。。你知道为什么吗?嗯:),你也可以使用session,但我正在尝试查找其他内容。你是否尝试从url获取id?我不知道我的代码有什么问题。。当我回显它时,它会显示“图像”。。可能是因为我在使用
if($this->session->userdata('is\u logged\u in')){
tooecho$this->session->userdata(“id”)时考虑了其他用户数据;在你的第二个函数中,让我看看你看到了什么。你已经知道表单验证集规则和一个你已经设置的规则。谢谢。我确实有验证,但我在这里没有提到它们。遗憾的是,我放弃了将其重定向到我需要$id的位置的想法。现在我将其重定向到正常函数(没有$id)您是否为重定向配置了routes.php示例
$route['item-page/(:any)]='item-page/index/$1';
否…我曾经有过它,但现在我已经这样删除了它。
/$route['property/(:num)]='listing/property_id_$1'
。它是一个完全不同的url。这很好