doupi1532 2013-05-11 21:19
浏览 49
已采纳

加载控制器codeigniter时如何保存信息?

I'm doing a proyect in Codeigniter. One of the views that I have requires to select a student and a account. The student and the account are in different views and controllers. I select the student successfully, and I fill some fields with the student information, but then I want to select the account and it fill the fields for the account, but the information for the student dissapears.

Here is the view that I'm working on:

<?php

    /*******Information for the student ********/
    $parametroExpediente = "";
    $parametroNombre = "";
    $parametroPrimerApellido = "";
    $parametroSegundoApellido = "";
    $parametroCedula = "";


    if (isset($expediente))
    {
        $parametroExpediente = set_value('expediente', $expediente);
        $parametroNombre = set_value('nombre', $nombre);
        $parametroPrimerApellido = set_value('primerApellido', $primerApellido);
        $parametroSegundoApellido = set_value('segundoApellido', $segundoApellido);
        $parametroCedula = set_value('cedula', $cedula);
    }
    /************************************/

    /*******Information for the account********/
    $parametroIDPlan = "";
    $parametroDescripcionPlan = "";
    $parametroTotalAPagarPlan = "";
    $parametroCuantosPagosPlan = "";
    $parametroFrecuenciaPagoPlan = "";
    $parametroAcivoPlan = "";
    $parametroIDCursoPlan = "";
    $parametroMultiGrupoPlan = "";

    if (isset($idPlan))
    {
        $parametroIDPlan = set_value('idPlan', $idPlan);
        $parametroDescripcionPlan = set_value('descripcion', $descripcion);
        $parametroTotalAPagarPlan = set_value('totalApagar', $totalApagar);
        $parametroCuantosPagosPlan = set_value('cuantosPagos', $cuantosPagos);
        $parametroFrecuenciaPagoPlan = set_value('cadaCuantosDiasPaga', $cadaCuantosDiasPaga);
        $parametroAcivoPlan = set_value('activo', $activo);
        $parametroIDCursoPlan = set_value('idCurso', $idCurso);
        $parametroMultiGrupoPlan = set_value('multiGrupo', $multiGrupo);    
    }
    /************************************/
?>

<!--BUTTON TO SELECT A STUDENT -->
<a href="http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/Alumnos_controller/loadAlumnoView/seleccionarParaCuenta" class="btn btn-primary">Seleccionar alumno</a>
<span class="badge badge-info">Expediente: <?php echo $parametroExpediente ?></span>
<!---------------------------------->
<br/>
<br/>
<br/>

<!--BUTTON TO SELECT AN ACCOUNT -->
<a href="http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/PlanDePago_controller/loadPlanDePagoView/seleccionarParaCuenta/" class="btn btn-primary">Seleccionar plan de pago</a>
<span class="badge badge-info">Plan escogido: <?php echo $parametroDescripcionPlan ?></span>

When the student and the account are selected, they both redirect their information to the same controller, which is the following:

<?php
class Cuentas_controller extends CI_Controller {

   public $data = array();

   public function __construct()
   {
        parent::__construct();
        // Your own constructor code

        $this->load->helper('url');

        $this->load->helper('form');

        $this->load->helper('url');

        $this->load->model('Alumnos_model');
        $this->load->model('PlanDePago_model');

    }

   function index()
   {
        $this->load->view('cuentas_view');
   }

   /*Take the information for the student*/
   function setStudent($elExpediente)
   {
       $query = $this->Alumnos_model->getAllData($elExpediente);
       foreach ($query->result_array() as $row)
       {
           $this->data = array(
                //'expediente' => $row['expediente'],
                'expediente' => $elExpediente,
                'primerApellido' => $row['primerApellido'],
                'segundoApellido' => $row['segundoApellido'],
                'nombre' => $row['nombre'],
                'cedula' => $row['cedula']
            );
       }
       $this->load->view('cuentas_view',$this->data);
   }

   /*Take the information for the account*/
   function setAccount($id)
   {           
       $query = $this->PlanDePago_model->getAllDataNoParameters($id);
       foreach ($query->result_array() as $row)
       {
           $this->data = array(
                'idPlan' => $id,
                'totalApagar' => $row['totalApagar'],
                'descripcion' => $row['descripcion'],
                'cuantosPagos' => $row['cuantosPagos'],
                'cadaCuantosDiasPaga' => $row['cadaCuantosDiasPaga'],
                'activo' => $row['activo'],
                'idCurso' => $row['idCurso'],
                'multiGrupo' => $row['multiGrupo']
            );
       }
       $this->load->view('cuentas_view',$this->data);
   }
}

?>

As you can see, the setStudent and setAccount methods take the information sent by those views, and then open the view that I'm working on and fill some information, but it's not working as expected, the first that I selected dissapears when I select the second one.

Some suggestion to get this working? I want both student and account showing information when I select them.

  • 写回答

2条回答 默认 最新

  • doulan9188 2013-05-12 00:24
    关注

    You don't save Expediente. In my example, we save $elExpediente and $idPlan in session variable, and redirect to view. Then in $this->load->view('cuentas_view') we load data about this Expediente and idPlan in view from models as one row each.

    Try like this, think I helped you.

    Controller

    class Cuentas_controller extends CI_Controller 
    {
       public function __construct()
       {
            parent::__construct();
    
            $this->load->helper('url');
            $this->load->helper('form');
            $this->load->helper('url');
    
            $this->load->model('Alumnos_model');
            $this->load->model('PlanDePago_model');
    
        }
    
        function index()
        {
             $this->load->view('cuentas_view', array(
                 'elExpediente' => $this->session->userdata('elExpediente'),
                 'idPlan'       => $this->session->userdata('idPlan'),
             ));
        }
    
        function flashParams()
        {
            // to erase session data elExpediente and idPlan
            $this->session->unset_userdata('elExpediente');
            $this->session->unset_userdata('idPlan');
        }
    
        function setAccount($id)
        {
            $this->session->set_userdata('idPlan', $id);
            redirect('http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/Cuentas_controller');
        }
    
        function setStudent($elExpediente)
        {
            $this->session->set_userdata('elExpediente', $id);
            redirect('http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/Cuentas_controller');
        }   
    }
    

    Alumnos_model:

    class Alumnos_model extends CI_Model
    {
        public function getItem($elExpediente)
        {
            $this->db->select('*');
            $this->db->where('someColumn', $elExpediente);
            $this->db->limit(1);
            $this->db->from('someTable');
            return $this->db->get()->row_array();
        }
    }
    

    PlanDePago_model:

    class PlanDePago_model extends CI_Model
    {
        public function getItem($id)
        {
            $this->db->select('*');
            $this->db->where('someIdColumn', $id);
            $this->db->limit(1);
            $this->db->from('someTable');
            return $this->db->get()->row_array();
        }
    }
    

    cuentas_view.php file:

    <?php
    
        /*******Information for the student ********/
        $parametroExpediente      = "";
        $parametroNombre          = "";
        $parametroPrimerApellido  = "";
        $parametroSegundoApellido = "";
        $parametroCedula          = "";
    
        /*******Information for the account********/
        $parametroIDPlan             = "";
        $parametroDescripcionPlan    = "";
        $parametroTotalAPagarPlan    = "";
        $parametroCuantosPagosPlan   = "";
        $parametroFrecuenciaPagoPlan = "";
        $parametroAcivoPlan          = "";
        $parametroIDCursoPlan        = "";
        $parametroMultiGrupoPlan     = "";
    
    
        if($row = $this->Alumnos_model->getItem($elExpediente))
        {
            $parametroExpediente      = set_value('expediente',      $elExpediente);
            $parametroNombre          = set_value('nombre',          $row['nombre']);
            $parametroPrimerApellido  = set_value('primerApellido',  $row['primerApellido']);
            $parametroSegundoApellido = set_value('segundoApellido', $row['segundoApellido']);
            $parametroCedula          = set_value('cedula',          $row['cedula']);
        }
    
        if($row = $this->PlanDePago_model->getItem($idPlan))
        {
            $parametroIDPlan             = set_value('idPlan',              $idPlan);
            $parametroDescripcionPlan    = set_value('descripcion',         $row['descripcion']);
            $parametroTotalAPagarPlan    = set_value('totalApagar',         $row['totalApagar']);
            $parametroCuantosPagosPlan   = set_value('cuantosPagos',        $row['cuantosPagos']);
            $parametroFrecuenciaPagoPlan = set_value('cadaCuantosDiasPaga', $row['cadaCuantosDiasPaga']);
            $parametroAcivoPlan          = set_value('activo',              $row['activo']);
            $parametroIDCursoPlan        = set_value('idCurso',             $row['idCurso']);
            $parametroMultiGrupoPlan     = set_value('multiGrupo',          $row['multiGrupo']);    
        }
    ?>
    
    your html code here
    

    not sure in set_value, i'm never use it

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法