在会话中保存下拉列表中的数据并在另一个页面中显示 Codeigniter
Save data from dropdown at session and show in another page Codeigniter
您好,我在使用 codeigniter 时遇到问题。
这里我想把通过下拉选中的数据保存到session中,然后把选中的数据展示到一个叫step4的页面。我已经试过了,但是当我显示数据时,它没有出现。
这是脚本:
控制器Step1.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Step1 extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
$this->load->model('M_datasiswa');
}
public function step1()
{
$data['departemen'] = $this->M_datasiswa->get_departemen();
$data['tahunajaran'] = $this->M_datasiswa->get_tahunajaran();
$this->load->view('v_step1',$data);
}
function save_data(){
$depart = $this->input->post('kode_departemen');
$tahun = $this->input->post('kode_tahun');
$asal = $this->input->post('kode_asal');
$data = array(
'departemen' => $depart,
'proses' => $tahun,
'asal' => $asal
);
$this->session->set_userdata($data);
redirect('step4');
}
}
v_step1.php
<form action="<?php echo base_url('Step1/save_data'); ?>" method="post">
<table border="0" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
<tr style="height:50px;">
<td style="width:100px;"> </td>
<td class="tulisanDalamTabel" colspan="2"> Departemen </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_departemen" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH UNIT--</option>
<?php
foreach ($departemen as $row) { echo "<option value='".$row->replid."'>".$row->departemen."</option>";}echo"</select>"?>
</td>
</tr>
<tr style="height:50px;" >
<td style="width:100px;"></td>
<td class="tulisanDalamTabel" colspan="2"> PPDB </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_tahun" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH TAHUN AJARAN--</option>
<?php
foreach ($tahunajaran as $row) { echo "<option value='".$row->replid."'>".$row->proses."</option>";}echo"</select>"?>
</td>
</tr>
<tr style="height:50px;">
<td style="width:100px;"></td>
<td class="tulisanDalamTabel" colspan="2"> Asal Calon Siswa </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_asal" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH--</option>
<option> UMUM </option>
<option> KELUARGA YAYASAN </option>
</td>
</tr>
<tr style="height:50px;">
<td colspan="8"><hr style="width: 98%"/></td>
</tr>
<tr style="height:50px;">
<td class="tulisanDalamTabel" colspan="2"><input type="submit" class="buttonKembali" value="Batal Daftar" style="vertical-align:middle"> </td>
<td colspan="4"> </td>
<td class="tulisanDalamTabel" style="text-align:right; width:380px"><input type="submit" class="buttonSelanjutnya" value="Selanjutnya" style="vertical-align:middle;"> </td>
</tr>
</table>
</form>
v_step4.php
<table border="1" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
<tr style="height:50px;">
<td class="tulisanDalamTabel"> Nama Lengkap </td>
<td> <input type="text" placeholder="Nama Lengkap" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;"/> </td>
<td> <?php $this->session->userdata('departemen') ?></td>
<td class="tulisanDalamTabel"> Nama Panggilan </td>
<td> <input type="text" placeholder="Nama Panggilan" class="tulisanDalamTabel" style="width:97%; margin-left: 1px; height:40px;"/> </td>
</tr>
谢谢,希望有人能帮助我。
您忘记使用 echo 进行打印
<td> <?php $this->session->userdata('departemen') ?></td>
改为这样做
<td> <?php echo $this->session->userdata('departemen') ?></td>
您好,我在使用 codeigniter 时遇到问题。 这里我想把通过下拉选中的数据保存到session中,然后把选中的数据展示到一个叫step4的页面。我已经试过了,但是当我显示数据时,它没有出现。
这是脚本:
控制器Step1.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Step1 extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
$this->load->model('M_datasiswa');
}
public function step1()
{
$data['departemen'] = $this->M_datasiswa->get_departemen();
$data['tahunajaran'] = $this->M_datasiswa->get_tahunajaran();
$this->load->view('v_step1',$data);
}
function save_data(){
$depart = $this->input->post('kode_departemen');
$tahun = $this->input->post('kode_tahun');
$asal = $this->input->post('kode_asal');
$data = array(
'departemen' => $depart,
'proses' => $tahun,
'asal' => $asal
);
$this->session->set_userdata($data);
redirect('step4');
}
}
v_step1.php
<form action="<?php echo base_url('Step1/save_data'); ?>" method="post">
<table border="0" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
<tr style="height:50px;">
<td style="width:100px;"> </td>
<td class="tulisanDalamTabel" colspan="2"> Departemen </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_departemen" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH UNIT--</option>
<?php
foreach ($departemen as $row) { echo "<option value='".$row->replid."'>".$row->departemen."</option>";}echo"</select>"?>
</td>
</tr>
<tr style="height:50px;" >
<td style="width:100px;"></td>
<td class="tulisanDalamTabel" colspan="2"> PPDB </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_tahun" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH TAHUN AJARAN--</option>
<?php
foreach ($tahunajaran as $row) { echo "<option value='".$row->replid."'>".$row->proses."</option>";}echo"</select>"?>
</td>
</tr>
<tr style="height:50px;">
<td style="width:100px;"></td>
<td class="tulisanDalamTabel" colspan="2"> Asal Calon Siswa </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_asal" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH--</option>
<option> UMUM </option>
<option> KELUARGA YAYASAN </option>
</td>
</tr>
<tr style="height:50px;">
<td colspan="8"><hr style="width: 98%"/></td>
</tr>
<tr style="height:50px;">
<td class="tulisanDalamTabel" colspan="2"><input type="submit" class="buttonKembali" value="Batal Daftar" style="vertical-align:middle"> </td>
<td colspan="4"> </td>
<td class="tulisanDalamTabel" style="text-align:right; width:380px"><input type="submit" class="buttonSelanjutnya" value="Selanjutnya" style="vertical-align:middle;"> </td>
</tr>
</table>
</form>
v_step4.php
<table border="1" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
<tr style="height:50px;">
<td class="tulisanDalamTabel"> Nama Lengkap </td>
<td> <input type="text" placeholder="Nama Lengkap" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;"/> </td>
<td> <?php $this->session->userdata('departemen') ?></td>
<td class="tulisanDalamTabel"> Nama Panggilan </td>
<td> <input type="text" placeholder="Nama Panggilan" class="tulisanDalamTabel" style="width:97%; margin-left: 1px; height:40px;"/> </td>
</tr>
谢谢,希望有人能帮助我。
您忘记使用 echo 进行打印
<td> <?php $this->session->userdata('departemen') ?></td>
改为这样做
<td> <?php echo $this->session->userdata('departemen') ?></td>