简体   繁体   English

Codeigniter:如何在重定向中传递搜索词

[英]Codeigniter :How to pass search term in redirect

i have made a simple project with codeigniter using PHP and MySQL. 我使用PHP和MySQL用codeigniter做了一个简单的项目。 The project gives the abillity to th user to manage his warehouse by adding new product and updating the stock of each one. 该项目使用户有能力通过添加新产品和更新每种产品的库存来管理其仓库。 Now when the user searches for a product and updates the stock value, the app updates the database and refreshes the page and showing all the products. 现在,当用户搜索产品并更新库存值时,该应用程序将更新数据库并刷新页面并显示所有产品。 Is there a way to pass the search term he used or even better the product that he changed in the redirect. 有没有一种方法可以传递他使用的搜索词,甚至可以更好地传递他在重定向中更改的产品。 Thanks a lot. 非常感谢。

function prevazia($param1 = '', $param2 = '', $param3 = '')
    {
        if ($this->session->userdata('admin_login') != 1)
            redirect(base_url() . 'index.php?login');
        if ($param1 == 'edit') 
        {
            $data['type']    = $this->input->post('type');   
            $data['color']   = $this->input->post('color');
            $addition   = $this->input->post('addition');
            $data['stock']   = $this->input->post('stock') + $addition;
            $data['stock_alert']   = $this->input->post('stock_alert');
            //-----------------------------------------
            include('dbc.php');
            mysqli_query($conn,"SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
            $sql9 = "SELECT * FROM prevazia_log order by id desc LIMIT 1";          
            $result = mysqli_query($conn, $sql9);
            if ($result->num_rows > 0) 
            {
                while($row = $result->fetch_assoc()) 
                {
                    $last_id=$row['id']+1;
                }
            }
            date_default_timezone_set('Europe/Athens');
            //$result6 =  mysqli_query($conn, $sql);
            //$additionDate = DateTime::createFromFormat('d/m/Y H:i');
            //$myAdditionDate = $additionDate->format('Y-m-d H:i');
            $log['id']                  = $last_id;
            $log['user']                = $this->session->userdata('name');
            $log['create_timestamp']    = date("d-m-y  h:i:sa");
            $log['type']                = $this->input->post('type');
            $log['color']               = $this->input->post('color');
            $log['previous_stock']      = $this->input->post('stock');
            $log['addition']            = $this->input->post('addition');
            $log['new_stock']           = $this->input->post('stock') + $this->input->post('addition');
            //--------------------
            //$data['role']   = $this->input->post('role');
            $this->db->insert('prevazia_log', $log);
            $this->db->where('id', $param2);
            $this->db->update('prevazia', $data);
            // UPLOAD IMAGE FILE
            $this->session->set_flashdata('flash_message', translate('informations_updated'));
            redirect(base_url() . 'index.php?admin/prevazia', 'refresh');
        }
        if ($param1 == 'delete') 
        {
            $this->db->where('id', $param2);
            $this->db->delete('prevazia');
            $this->session->set_flashdata('flash_message', translate('data_deleted'));
            redirect(base_url() . 'index.php?admin/prevazia', 'refresh');
        }
        $page_data['page_name']  = 'prevazia';
        $page_data['page_title'] = 'Πρεβάζια';
        $page_data['prevazia']  = $this->db->get_where('prevazia', array('active'=> $GLOBALS['flag']))->result_array();
        $this->load->view('backend/index', $page_data);
    }

EDIT : the best would be if i could pass the $data['type'] and $data['color'], so when it redirects it will pass these values to the search box. 编辑:最好是如果我可以传递$ data ['type']和$ data ['color'],那么当它重定向时,会将这些值传递给搜索框。

You should return the search param via view,if you are using form submit with method post 如果您使用带方法post的表单提交,则应通过视图返回搜索参数

$data['search_param'] =  $post['search_param'];
$this->load->view('view_page', $data);

<input name="search_param"  value="<?php echo !empty($search_param) ? $search_param : ''?>">

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

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