How to call function of controller in view using codeIgniter? [duplicate]

妖精的绣舞 提交于 2019-12-13 09:06:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!