我有控制器叫'项目'显示在db通过视图和每个项目链接旁边保存的所有项目,以查看其详细信息,即将项目ID发送到控制器以选择单击的项目并显示其详细信息。 我需要将项目id存储在会话变量中,以便在我的所有进程中使用它。 我的问题是: 当我调用项目id会话变量时 - >在第一次调用它正确显示它 - >但在第二次调用它时显示' js'或者&#c;' 我无法知道我的项目ID和' js'之间的关系。或者&#c;' ?? 价值变动的原因???
这是我的代码:
admin_projects_view_view.php
<br />
<br />
<!--Page Container Start Here-->
<section class="main-container">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="widget-wrap">
<div class="widget-header block-header margin-bottom-0 clearfix">
<div class="pull-left">
<h3 style="font-size:25px">Projects</h3>
<p></p>
</div>
</div>
<div class="widget-container">
<div class="widget-content">
<!-------------------------- Projects---------------------------->
<div class="row">
<div class="col-md-12">
<a href="#" class="button round" data-reveal-id="newproject">Add New</a>
<table id="headerTable" class="tablee">
<tr>
<td class="event-td td-head text-center">ID</td>
<td class="event-td td-head text-center">Name</td>
<td class="event-td td-head text-center">Location</td>
<td class="event-td td-head text-center">Description</td>
<td class="event-td td-head text-center">Quality</td>
<td class="event-td td-head text-center">Payment Method</td>
<td class="event-td td-head text-center">Project Map</td>
<td class="event-td td-head text-center">Action</td>
</tr>
<?php
foreach($view_projects as $row)
{
?>
<tr>
<td class="event-td text-center"><?php echo $row->id ?></td>
<td class="event-td text-center"><?php echo $row->pname?></td>
<td class="event-td text-center"><?php echo $row->location ?></td>
<td class="event-td text-center"><?php echo $row->description ?></td>
<td class="event-td text-center"><?php echo $row->stars ?></td>
<td class="event-td text-center"><?php echo $row->payment_methods ?></td>
<td class="event-td text-center"><?php echo $row->project_map ?></td>
<td class="event-td text-center">
<a href="<?php echo site_url();?>/projects/view_project_details/<?php echo $row->id;?>">View Details </a>
</td>
<?php } ?>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="newproject" class="reveal-modal" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h2 id="modalTitle">Add New Project</h2>
<form action="<?php echo site_url('projects/add_new'); ?>" enctype="multipart/form-data" method="post" data-abide>
<label>Project Name: <small>required</small>
<input type="text" name="pname" placeholder="Project Name" >
</label>
<label>Location: <small>required</small>
<input type="text" name="location" placeholder="Project Location" >
</label>
<label>Description: <small>required</small>
<textarea name="description" placeholder="Project Description" /></textarea>
</label>
<label>Quality: <small>required</small>
<input type="text" name="stars" placeholder="Project Quality" >
</label>
<label>Payment Method: <small>required</small>
<input type="text" name="payment_methods" placeholder="Payment Method" >
</label>
<label>Map: <small>required</small>
<textarea name="project_map" placeholder="Project Map" /></textarea>
</label>
<input type="submit" value="Save" name="submit" class="button round" />
</form>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
项目控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Projects extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper("session");
$this->load->helper("url");
$this->load->model('projects_model');
$this->load->helper('cookie');
}
public function index()
{
$this->load->model('projects_model');
$data['view_projects'] = $this->projects_model->view_projects();
$this->load->view('admin_header_view');
$this->load->view("admin_menu_view");
$this->load->view("admin_projects_view_view", $data);
$this->load->view('admin_footer_view');
}
public function view_project_details($id)
{
$sessdata=array(
'project_id'=>$id
);
$this->session->set_userdata($sessdata);
$data['view_projects_services'] = $this->projects_model->view_projects_services($id);
$data['view_projects_spaces'] = $this->projects_model->view_projects_spaces($id);
$data['view_projects_prices'] = $this->projects_model->view_projects_prices($id);
$data['view_projects_photos'] = $this->projects_model->view_projects_photos($id);
$data['view_projects_videos'] = $this->projects_model->view_projects_videos($id);
$data['view_projects_status'] = $this->projects_model->view_projects_status($id);
$this->load->view('admin_header_view');
$this->load->view("admin_menu_view");
$this->load->view("admin_projects_details_view", $data);
$this->load->view('admin_footer_view');
}
public function view_project_details_session()
{
$id = $this->session->userdata('project_id');
//$data['view_one_project'] = $this->projects_model->view_one_project_session($id);
$data['view_projects_services'] = $this->projects_model->view_projects_services($id);
$data['view_projects_spaces'] = $this->projects_model->view_projects_spaces($id);
$data['view_projects_prices'] = $this->projects_model->view_projects_prices($id);
$data['view_projects_photos'] = $this->projects_model->view_projects_photos($id);
$data['view_projects_videos'] = $this->projects_model->view_projects_videos($id);
$data['view_projects_status'] = $this->projects_model->view_projects_status($id);
$this->load->view('admin_header_view');
$this->load->view("admin_menu_view");
$this->load->view("admin_projects_details_view", $data);
$this->load->view('admin_footer_view');
}
//////////////////////////////////// Projects ////////////////////////////////////////////
public function add_new_project()
{
$data= array(
'pname' => $this->input->post('pname'),
'location' => $this->input->post('location'),
'description' => $this->input->post('description'),
'stars' => $this->input->post('stars'),
'payment_methods' => $this->input->post('payment_methods'),
'project_map' => $this->input->post('project_map')
);
$this->db->insert('projects',$data);
redirect('projects');
}
public function edit_project($id)
{
$this->load->model('projects_model');
$data['one_project'] = $this->projects_model->view_one_project($id);
$this->load->view('admin_header_view');
$this->load->view("admin_menu_view");
$this->load->view("admin_projects_edit_view", $data);
$this->load->view('admin_footer_view');
}
public function save_project()
{
$project_id = $this->input->post('project_id');
$data= array(
'pname' => $this->input->post('pname'),
'location' => $this->input->post('location'),
'description' => $this->input->post('description'),
'stars' => $this->input->post('stars'),
'payment_methods' => $this->input->post('payment_methods'),
'project_map' => $this->input->post('project_map')
);
$this->db->where('id',$project_id);
$this->db->update('projects',$data);
redirect('projects');
}
public function delete_project($id)
{
$this->db->where('id',$id);
$this->db->delete('projects');
redirect('projects');
}
}
projects_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class projects_model extends CI_Model{
public function view_projects()
{
$query=$this->db->get('projects');
return $query->result();
}
public function view_one_project($id)
{
$this->db->where('id',$id);
$query=$this->db->get('projects');
return $query->row();
}
}
打印会话变量值,如:
<? echo $this->session->userdata('project_id');?>
admin_footer_view.php
<!--Footer Start Here -->
<footer class="footer-container">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="footer-left">
<span>© 2016 <a href="http://example.com"></a></span>
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="footer-right">
<span class="footer-meta">Designed by <a href="#"></a></span>
</div>
</div>
</div>
</div>
</footer>
<!--Footer End Here -->
</section>
<!--Page Container End Here-->
<!--Rightbar Start Here--><!--Rightbar End Here-->
<script src="<?php echo base_url();?>/js/lib/jquery.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery-migrate.js"></script>
<script src="<?php echo base_url();?>/js/lib/bootstrap.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.ui.js"></script>
<script src="<?php echo base_url();?>/js/lib/jRespond.js"></script>
<script src="<?php echo base_url();?>/js/lib/nav.accordion.js"></script>
<script src="<?php echo base_url();?>/js/lib/hover.intent.js"></script>
<script src="<?php echo base_url();?>/js/lib/hammerjs.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.hammer.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.fitvids.js"></script>
<script src="<?php echo base_url();?>/js/lib/scrollup.js"></script>
<script src="<?php echo base_url();?>/js/lib/smoothscroll.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.slimscroll.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.syntaxhighlighter.js"></script>
<script src="<?php echo base_url();?>/js/lib/velocity.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery-jvectormap.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery-jvectormap-world-mill.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery-jvectormap-us-aea.js"></script>
<script src="<?php echo base_url();?>/js/lib/smart-resize.js"></script>
<!--iCheck-->
<script src="<?php echo base_url();?>/js/lib/icheck.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.switch.button.js"></script>
<!--CHARTS-->
<script src="<?php echo base_url();?>/js/lib/chart/sparkline/jquery.sparkline.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/easypie/jquery.easypiechart.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/excanvas.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/curvedLines.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.time.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.stack.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.axislabels.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.resize.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.tooltip.min.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.spline.js"></script>
<script src="<?php echo base_url();?>/js/lib/chart/flot/jquery.flot.pie.min.js"></script>
<!--Forms-->
<script src="<?php echo base_url();?>/js/lib/jquery.maskedinput.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.validate.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.form.js"></script>
<script src="<?php echo base_url();?>/js/lib/j-forms.js"></script>
<script src="<?php echo base_url();?>/js/lib/jquery.loadmask.js"></script>
<script src="<?php echo base_url();?>/js/lib/vmap.init.js"></script>
<script src="<?php echo base_url();?>/js/lib/theme-switcher.js"></script>
<script src="<?php echo base_url();?>/js/apps.js"></script>
<script src="<?php echo base_url();?>/js/foundation/foundation.js"></script>
<script src="<?php echo base_url();?>/js/foundation/foundation.reveal.js"></script>
<script src="<?php echo base_url();?>/js/foundation/foundation.abide.js"></script>
<script src="<?php echo base_url();?>/js/foundation/foundation.offcanvas.js"></script>
<script src="<?php echo base_url();?>/js/foundation/foundation.topbar.js"></script>
<script src="<?php echo base_url();?>/js/foundation/foundation.tooltip.js"></script>
<script>
$(document).foundation();
</script>
</body>
</html>
请知道
答案 0 :(得分:0)
您正在设置会话变量名称:&#39; project_id&#39;
但是在方法&#34; view_project_details_session&#34;中,您正试图获得&#39; pid&#39; 变量名称不同。