Php 在codeigniter中从视图调用函数不工作
我使用基本url从视图调用控制器函数,它将转到该函数,但显示未找到404页。 .htaccess我用的是这个吗Php 在codeigniter中从视图调用函数不工作,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我使用基本url从视图调用控制器函数,它将转到该函数,但显示未找到404页。 .htaccess我用的是这个吗 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L,QSA] </IfModule> 自动
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
自动加载是
$autoload['helper'] = array('form', 'url', 'security');
routes.php中的默认控制器是
$route['default_controller'] = 'prog_bar';
基本url是
$config['base_url'] = 'http://localhost:8080/jsLearning/prog_bar/';
看法
a href=”“>abc
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class prog_bar extends CI_Controller {
public function index()
{
$this->load->view('prog_bar_view');
}
public function file_func(){
echo "form";
}
}
您的基本url
错误。应该是
$config['base_url'] = 'http://localhost:8080/jsLearning/';
现在在HTML中使用site\u url()
代替base\u url()
类似
<a href="<?php echo site_url('prog_bar/file_func'); ?>">abc</a>
类名应以大写字母开头,
改变这个
class prog_bar extends CI_Controller {
到
我认为您应该对以下设置非常满意:
在Config.php中:
$config['base_url'] = 'http://localhost:8080/jsLearning/';
在你看来:
<a href="<?php echo base_url(); ?>file_func">abc</a>
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
如果仍然有错误,请检查基本url链接指向的内容。创建链接
<a href="<?php echo base_url(); ?>">Base Url</a>
在浏览器中查看链接的位置。网站内的链接不使用基本url。使用控制器名称和方法名称
<?php echo anchor("Pages/entry", "Post Entry"); ?>
函数不会简单地显示视图或代码段而不被告知其位置。如果您试图在页面中包含表单,那么只需使用嵌套视图,并在主(html)视图中使用$this->load->view()加载您试图显示的视图即可。能否显示您试图访问的URL<代码>http://localhost:8080/jsLearning/prog_bar/file_func
?答案已更新。将您的.htaccess
更改为answerNOP NOT working中的内容。如果使用或,会发生什么情况?您使用的是windows还是linux?
<a href="<?php echo base_url(); ?>file_func">abc</a>
class Prog_bar extends CI_Controller {
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<a href="<?php echo base_url(); ?>">Base Url</a>
<?php echo anchor("Pages/entry", "Post Entry"); ?>
$this->load->view('prog_bar_view')