从视图中获取“id”并传递到Grocery Crud CodeIgniter中的另一个视图

时间:2013-02-06 13:51:29

标签: codeigniter

我是Code Igniter的Grocery Crud的新手,需要帮助。我有桌子vaboteni(雇员),它运作良好。但我陷入了代码添加更多行动。当我单击添加操作按钮时,我收到错误404 Page Not Found。我想从表中的一行获取“id”并传递到另一个视图,以便仅显示一个员工的数据。我在本地服务器上有站点,地址为localhost / bis_resursi / index.php / vraboteni / vraboteni_managment

这是我的Controller vraboteni.php

     function vraboteni_management()
     {
        $crud = new grocery_CRUD();

        $crud->set_theme('datatables');
        $crud->set_table('vraboteni');
        $crud->set_subject('вработен');
        .....

        $crud->add_action('Преглед', '', 'vraboteni/vraboten_managment/pregled','ui-icon-plus');

        function pregled($id)
        {
            $this->load->model("vraboteni_pregled_model");
            $data["result"] = $this->getVraboteniPregled($vrabotenID);
            $this->load->view("pregled", $data);

        }

        $output = $crud->render();

        $this->_example_output($output);
        }

和型号:vraboteni_pregled_model.php

        <?php
        class Vraboteni_Pregled_Model  extends CI_Model  {
            function __construct()
            {
                parent::__construct();
            }
        }

        function getVraboteniPregled($id){
            $query = $this->db->query("SELECT * FROM vraboteni WHERE vraboteID = '$id' ");

            return $query->result();
        }

并且在视图中vraboten_view.php我把

    <?=$query['vrabotenID']?>
    <br>
    Hi, I'am <?=$query['ime']?>
    <br>
    from<?=$query['adresa']?>

1 个答案:

答案 0 :(得分:1)

我设法找到解决方案。正确的代码是:

Controller vraboteni.php

 $crud->add_action('Преглед', '', 'vraboteni/get','ui-icon-plus');

    $output = $crud->render();
    $this->_example_output($output);
    }


    function vraboteni()
    {
    $crud = new grocery_crud();

    $crud->set_table('vraboteni');


    $output = $crud->render();

    print_r($output);

    }

function getall()
{
    $this->load->model('vraboten_model');
    $data['query']=$this->vraboten_model->vraboten_getall();
    $this->load->view('vraboten_view',$data);
}
function get($vrabotenID)
{
    $this->load->model('vraboten_model');
    $data['query']=$this->vraboten_model->vraboten_get($vrabotenID);
    $this->load->view('vraboten_view',$data);
}

模型vraboten_model.php

<?php

类Vraboten_model扩展了CI_Model {

function vraboten_model(){
    parent::__Construct();
}

function  vraboten_getall(){
    $this->load->database();
    $query=$this->db->get(' vraboteni');
    return $query->result();
}
function  vraboten_get($vrabotenID){
    $this->load->database();
    $query=$this->db->get_where(' vraboteni',array('vrabotenID'=>$vrabotenID));
    return $query->row_array();
}

}

并查看vraboten_view.php

    <?=$query['vrabotenID']?>
<br>
Hi, I'am <?=$query['ime']?>
<br>
from<?=$query['adresa']?>