我有以下控制器 -
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->database();
$catid = $this->input->post('cat');
if(isset($catid)){
$this->filter($catid);
}
}
private function filter($catid){
$sql = "select * from news_master where instr(concat(',', `Category`, ','), ', $catid ,') <> 0 ";
echo $sql;
}
}
提交表单时调用它。如果我提交表单,控制器会调用filter
函数并打印$sql
。奇怪的是,在它下面我得到默认404错误消息。
这是截图。!
我无法理解可能的原因。
答案 0 :(得分:1)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->database();
}
public function index()
{
$catid = $this->input->post('cat');
if(isset($catid)){
$this->filter($catid);
}
}
private function filter($catid){
$sql = "select * from news_master where instr(concat(',', `Category`, ','), ', $catid ,') <> 0 ";
echo $sql;
}
}
注意到你从构造函数中调用它。它应该在索引函数中。
答案 1 :(得分:0)
私人功能不会在codeigniter中充当页面
private function filter($catid){
$sql = "select * from news_master where instr(concat(',', `Category`, ','), ', $catid ,') <> 0 ";
echo $sql;
}
需要更新为PUBLIC
public function filter($catid){
$sql = "select * from news_master where instr(concat(',', `Category`, ','), ', $catid ,') <> 0 ";
echo $sql;
}