你好,我有一个使用codeigniter的php代码。它在本地主机上运行得很好。当我把它上传到肥牛服务器后,它就失败了。但不完全只有一个控制器。有四个控制器(页面,帖子,培训,用户),每个控制器工作良好,除了帖子。当我尝试加载posts控制器的函数时,它显示了500条错误消息。
我尝试将posts控制器重命名为reports,它的模型report也重命名为视图,但它并没有解决我的问题
current file names:
model: report.php
controller: reports.php
view: report/index.php, report/view.php*编辑这里是reports.php *
class Reports extends MY_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
//Pagination Configuration
$this->custom_config["total_rows"] = $this->report->record_count($tag);
$this->custom_config["per_page"] = 5;
$choice = $this->custom_config["total_rows"] / $this->custom_config["per_page"];
$this->custom_config["num_links"] = round($choice);
$this->pagination->initialize($this->custom_config);
$page = ($this->uri->segment($this->custom_config["uri_segment"])) ? $this->uri->segment($this->custom_config["uri_segment"]) : 0;
$data['tags'] = explode(',', $this->report->tags()['tags']);
$data['tags'] = array_unique($data['tags']);
$data['reports'] = $this->report->get($this->custom_config["per_page"], $page);
$this->load->view('template/head');
$this->load->view('template/header');
$this->load->view('reports/index', $data);
$this->load->view('template/footer', $this->footer);
}
public function tag($tag = FALSE) {
$tag = ($tag !== FALSE) ? urldecode($tag) : $tag;
//Pagination Configuration
$this->custom_config["total_rows"] = $this->report->record_count($tag);
$this->custom_config["per_page"] = 5;
$choice = $this->custom_config["total_rows"] / $this->custom_config["per_page"];
$this->custom_config["num_links"] = round($choice);
$this->pagination->initialize($this->custom_config);
$page = ($this->uri->segment($this->custom_config["uri_segment"])) ? $this->uri->segment($this->custom_config["uri_segment"]) : 0;
$data['tags'] = explode(',', $this->report->tags()['tags']);
$data['tags'] = array_unique($data['tags']);
$data['reports'] = $this->report->get($this->custom_config["per_page"], $page, FALSE, $tag);
$this->load->view('template/head');
$this->load->view('template/header');
$this->load->view('reports/index', $data);
$this->load->view('template/footer', $this->footer);
}
public function view($slug) {
$data['tags'] = explode(',', $this->report->tags()['tags']);
$data['tags'] = array_unique($data['tags']);
$data['report'] = $this->report->get(1, 0, $slug);
if(empty($data['report'])) {
show_404();
} else {
$this->load->view('template/head');
$this->load->view('template/header');
$this->load->view('reports/view', $data);
$this->load->view('template/footer', $this->footer);
}
}
}*编辑这里是report.php (模型)*
class Report extends CI_Model {
function __construct() {
parent::__construct();
}
function record_count($tag = FALSE) {
$this->db->from('categories');
$this->db->join('contents','categories.id = contents.category_id');
$this->db->where('categories.name', 'post');
if ($tag !== FALSE) {
$this->db->like('status', $tag);
}
return $this->db->count_all_results();
}
function get($limit, $start, $slug = FALSE, $tag = FALSE) {
if($this->session->userdata('language') == 'english') {
$this->db->select('slug, status, name_en as name, content_en as content, started_on, ended_on, admins.name as author');
} else {
$this->db->select('slug, status, contents.name, content, started_on, ended_on, admins.name as author');
}
$this->db->limit($limit, $start);
$this->db->from('categories');
$this->db->join('contents','categories.id = contents.category_id');
$this->db->join('admins','admins.id = contents.admin_id');
$this->db->where('categories.name', 'post');
$this->db->order_by("contents.id", "desc");
if ($tag !== FALSE) {
$this->db->like('status', $tag);
}
if ($slug !== FALSE) {
$this->db->where('slug', $slug);
$query = $this->db->get();
return $query->row_array();
}
$query = $this->db->get();
return $query->result_array();
}
function get_footer() {
if($this->session->userdata('language') == 'english') {
$this->db->select('slug, name_en as name');
}
$this->db->from('categories');
$this->db->join('contents','categories.id = contents.category_id');
$this->db->where('categories.name', 'post');
$this->db->order_by("contents.id", "desc");
$this->db->limit(2);
$query = $this->db->get();
return $query->result_array();
}
function tags() {
$this->db->select('group_concat(status) as tags');
$this->db->from('categories');
$this->db->join('contents','categories.id = contents.category_id');
$this->db->where('categories.name', 'post');
$query = $this->db->get();
return $query->row_array();
}
}发布于 2014-09-18 09:37:37
好的,首先,这是我的错,感谢Michael O'Brien。并发布了解决方案。希望有一天能帮上忙。
问题在于mysql版本。我在script上使用了concat_group,它的工作能力仅大于MySQL5.6。版本为5.5。我用下面的内容代替了group_concat,它起作用了。
function tags() {
$this->db->select('status as tag');
$this->db->from('categories');
$this->db->join('contents','categories.id = contents.category_id');
$this->db->where('categories.name', 'post');
$query = $this->db->get();
return $query->result_array();
}
$temp = '';
$data['tags'] = $this->mpost->tags();
foreach ($data['tags'] as $row) {
$temp .= $row['tag'].",";
}
$data['tags'] = explode(',', $temp);
$data['tags'] = array_unique($data['tags']);https://stackoverflow.com/questions/25906847
复制相似问题