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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器