Reputation: 787
I've this following controller -
<?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;
}
}
It's called when form is submitted. If I submit the form, controller calls filter
function and prints $sql
. And strange thing is that, below it I get default 404 error message.
Here's a screenshot.!
I can't understand the possible reason.
Upvotes: 0
Views: 113
Reputation: 768
<?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;
}
}
Just noticed your calling it from the constructor function. It should be in the index function.
Upvotes: 1
Reputation: 1069
Private functions dont act as pages in codeigniter
private function filter($catid){
$sql = "select * from news_master where instr(concat(',', `Category`, ','), ', $catid ,') <> 0 ";
echo $sql;
}
needs to be updated to PUBLIC
public function filter($catid){
$sql = "select * from news_master where instr(concat(',', `Category`, ','), ', $catid ,') <> 0 ";
echo $sql;
}
Upvotes: 0