无法使用CodeIgniter从同一PHP类中的方法加载查询结果 [英] Can't load query result from method in same PHP Class using CodeIgniter

查看:71
本文介绍了无法使用CodeIgniter从同一PHP类中的方法加载查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图'customer_name.php':

I have a view 'customer_name.php':

<html>
<body>	
	<?php						
	     foreach($names as $name){
		$details = anchor('customer/show_details/'.$name->customer_id, $name->customer_nama);
	        $link = anchor('customer/delete/'.$name->customer_id, 'HAPUS');
		$this->table->add_row($details,$link);
	        }
	echo $this->table->generate();
	echo $this->pagination->create_links(); 
	?>
</body>
</html>



a controller'customer.php':


a controller 'customer.php':

<?php

defined('BASEPATH') or exit('No direct access allowed');

class Customer extends CI_Controller{	

	function __construct(){
		parent:: __construct();
		$this->load->helper(array('form','url','html'));
		$this->load->library(array('session','table','pagination'));	
		$this->load->helper(array('form','url','html'));
		$this->load->model('customer_model');	
	}
	
	function show_name(){
		$customer = $_SESSION['name'];
		
		// pagination configuration
		$config['base_url'] = base_url().'customer/show_name/';
		$config['total_rows'] = $this->customer_model->get_rows_total();
		$config['per_page'] = 5; // query per page
		$config['uri_segment'] = 3;

		$config['use_page_numbers'] = TRUE;
		$config['full_tag_open'] = '<ul class="pagination">';
		$config['full_tag_close'] = '</ul>';
		
		$config['first_link'] = '« First';
		$config['first_tag_open'] = '<li class="first page">';
		$config['first_tag_close'] = '</li>';
		
		$config['last_link'] = 'Last »';
		$config['last_tag_open'] = '<li class="last page">';
		$config['last_tag_close'] = '</li>';
		
		$config['next_link'] = 'Next →';
		$config['next_tag_open'] = '<li class="next page">';
		$config['next_tag_close'] = '</li>';
		
		$config['prev_link'] = '← Previous';
		$config['prev_tag_open'] = '<li class="previous page">';
		$config['prev_tag_close'] = '</li>';		
		
		$config['cur_tag_open'] = '<li class="active"><a href="#">';
		$config['cur_tag_close'] = '</a></li>';
		
		$config['num_tag_open'] = '<li class="page">';
		$config['num_tag_close'] = '</li>';
		
		$this->pagination->initialize($config);
		
		//table configuration
		$tmpl = array('table_open' => '<table class="table table-bordered table-striped table-condensed">');
		$this->table->set_template($tmpl);
		$header = array('Nama', 'Action');
		$this->table->set_heading($header);
		$offset = ($this->uri->segment(3))? ($this->uri->segment(3)-1)*$config['per_page']:0;
		
		$data['names'] = $this->customer_model->show_name($config['per_page'], $offset);
		
		$this->load->view('customer_name',$data);
	}
	
	function show_details($id){//a bunch of code}
	
	function show_add_form(){//a bunch of code}
	
	function add(){
                //a bunch of code
		$this->show_name();
	}
	
	function update(){//a bunch of code}
	
	function delete($id){
		$this->customer_model->delete($id);
		$this->show_name();
	}
	
}

/* End of file Administrator.php */
/* Location : D:\Dropbox\www\order\application\controllers\Administrator.php */





和型号'customer_model.php ':



and a model 'customer_model.php':

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Customer_model extends CI_Model{

	function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	function get_rows_total(){
		return $this->db->count_all('customers');
	}
	
	function show_name($limit, $offset){
		$this->db->select('customer_id , customer_nama');
		return $query = $this->db->get('customers', $limit, $offset)->result();
	}
	
	function show_details($id){//a bunch of code}
	
	function add(){//a bunch of code}
	
	function update(){//a bunch of code}

	
	function delete($id){
		$this->db->query("DELETE FROM customers WHERE customer_id = '$id'");
	}
	
}





当我试图删除客户数据时遇到问题。控制器delete()应该调用show_name(),customer_name.php显示客户数据,但不是。但是当我使用add()时,customer_name.php显示客户数据。刷新页面时,数据就在那里。但是当我删除数据时,它什么都没有显示..我不知道为什么会出现这个问题。

我感谢你的任何帮助。很抱歉这篇文章很长。



I got a problem when i tried to delete a customer data. The controller delete() should call show_name() and customer_name.php shows the customer data, but it don't. But when i use add(), the customer_name.php shows the customer data. When refresh the page, the data is there. But when i delete a data, it shows nothing.. I don't have any idea why this problem occur.
I appreciate any help from you. Sorry for the long post.

推荐答案

命名为


name){
name){


details = anchor('' customer / show_details /'
details = anchor('customer/show_details/'.


这篇关于无法使用CodeIgniter从同一PHP类中的方法加载查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆