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条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化