I’m a fresh learner in using CI, below is a controller with function insertValues() that I try to call directly in URL, which looks like http://sitename/codeIgniter/pages/insertValues, but it returned 404 Page Not Found when its call, after few searched in google, I found that is an issue of route.php which I do not know how to configure it.
Please refer to below route.php, the function insertValues() will work only if remove $route[’(:any)’] = ‘pages/index/$1’;, but somehow once I call page like http://sitename/codeIgniter/home, it will show 404 Page Not Found.
route.php
$route['default_controller'] = 'pages/index';
$route['(:any)'] = 'pages/index/$1';Controller:
class Pages extends CI_Controller{
public function view($page='home'){
if(!file_exists('application/views/pages/'.$page.'.php')){
show_404();
}
$data['title'] = ucfirst($page);
$this->load->helper('url');
$this->load->model('getdb');
$data['results'] = $this->getdb->getAll();
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
//$this->insertValues();
}
function insertValues(){
$this->load->model('getdb');
$newRow = array(
'name' => 'andy'
);
$this->getdb->insert1($newRow);
echo "inserted!";
}
}Please help in advice, many thanks.