我是CodeIgniter的新手,我在从默认类中调用函数时遇到了麻烦。
控制器<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller
{
public function index()
{
$this->welcome();
}
public function welcome()
{
$this->load->view('view_welcome');
}
}
htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /pickme/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
目前它正在默认调用这个主控制器,正如我所期望的。
e。g
localhost/sitename
AND
localhost/sitename/index.php
AND
localhost/sitename/index.php/main/index
(All have the same result)
所以我觉得
localhost/sitename/class/function/id
将是如何htaccess将工作,但我得到一个404错误,当我尝试访问
localhost/sitename/main/welcome
尝试使用用户手册中建议的重写规则。
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我不是快速重写模块的专家,但是你的模块看起来肯定是错的。您不希望从浏览器访问应用程序和系统文件夹。最好的做法是把它放在你的根目录之外。
此外,我认为没有理由从索引方法中调用welcome方法,而只是将逻辑保留在索引控制器中。
但是你的想法是:
hostname/folder/class/function/parameters
是非常正确的:)
最后但并非最不重要的是,您可能忘记在config.php中保留索引文件空白,如果您想删除index.php.
,则需要这样做。祝你好运(:
编辑:试着在你的htaccess文件中使用:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index'.php|images|robots'.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>
在config.php中记得添加一个斜杠。