0

我有以下控制器-

<?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 错误消息。这是截图。!在此处输入图像描述

我无法理解可能的原因。

4

2 回答 2

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;
}

}

刚刚注意到您从构造函数调用它。它应该在索引函数中。

于 2013-08-12T22:40:57.243 回答
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;
}
于 2013-08-12T16:21:04.523 回答