如何使用codeIgniter调用视图中的控制器功能? [英] How to call function of controller in view using codeIgniter?
问题描述
使用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";
}
}
,并在视图m中使用HTML表单这样做之后,通过使用以下链接localhost / Codeignator / myController / myFn
来执行myFn的表单操作,我得到了以下错误!
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!
在此服务器上找不到请求的URL / CodeIgniter / myController / myFn
The requested URL /CodeIgniter/myController/myFn was not found on this server
但是当我使用链接localhost / Codeignator时/index.php/myController/myFn
but when I use the link localhost/Codeignator/index.php/myController/myFn
我得到了正确的输出!
推荐答案
默认情况下,index.php文件将包含在您的网址
中,请参阅用户指南部分删除有关添加.htacces的index.php文件
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
创建具有以下内容的.htaccess文件:
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
这篇关于如何使用codeIgniter调用视图中的控制器功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!