问题
Possible Duplicate:
How to call controller function from view in codeigniter?
With codeigniter, I have a controller as in the following:
class myController extends CI_Controller{
function __constructor(){
parent::__constructor();
}
public function index(){
$this->load->view('myview');
}
public function myFn(){
echo "my controller is called";
}
}
and in the view m using a HTML form in the form action m calling the myFn by using the following link localhost/Codeignator/myController/myFn after doing so I got the following error!
The requested URL /CodeIgniter/myController/myFn was not found on this server
but when I use the link localhost/Codeignator/index.php/myController/myFn
I got the correct output!
回答1:
By default, the index.php file will be included in your URLs see the user guide section Removing the index.php file about adding a .htacces
Create a .htaccess file with the following contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and put it in the root folder of your site
来源:https://stackoverflow.com/questions/11682604/how-to-call-function-of-controller-in-view-using-codeigniter