index.php/index/index 问题
本帖最后由 dbwolf 于 2009-8-31 00:43 编辑当类名称是index的时候
<?php
class Index extends Controller {
function Index()
{
parent::Controller();
$this->load->view('welcome_message');
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
<?php
class Index extends Controller {
function Index()
{
// parent::Controller();
$this->load->view('welcome_message');
}
如果没有 // parent::Controller();
也会出现错误
编译后出现了2个,,welcome_message 的·内容
把方法写在构造函数中是不是出现那个问题。。。
考虑是不是与自动执行构造函数有关???
然后index.php/index/index的时候 ,先默认执行function Index()
再一次执行了index的方法??
另外想问一下,,ci默认的类名称是不是就是welcome。。能不能修改,默认的方法是index,能不能修改啊。谢谢了 本帖最后由 dbwolf 于 2009-8-31 00:39 编辑
<?php
class Index extends Controller {
function Index()
{
parent::Controller();
$this->load->view('welcome_message');
}
function index1(){
parent::Controller();
$this->load->view('welcome_message');
}
}
http://localhost/index.php/index/index2个===http://localhost/index.php/index/2个
http://localhost/index.php/index/index1 2个
只要构造函数中多了
$this->load->view('welcome_message');
以后的方法中就会多出一个welcome_message。。。 这是php基础知识,与类名相同的方法就是构造方法,实例化时候会被执行
而你的action又是index,所以index会被执行两次 请不要用 index,属于 CI 特殊关键字,用 CI 就要遵守某些规则,呵呵 <Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /CodeIgniter/index.php/$1
</IfModule>
但是url中还是有index.php 本帖最后由 yinzhili 于 2009-8-31 14:33 编辑
index是保留字,不能用作控制器名称。
http://codeigniter.org.cn/user_guide/general/reserved_names.html 我输入下面的url是没有问题的
http://localhost/CodeIgniter/index.php/register
但是我输入这个url
http://localhost/CodeIgniter/register
HTTP 404 - 未找到文件
apache 我也载入了mod_rewrite我也载入了
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /CodeIgniter/index.php/$1
</IfModule> .htaccess 文件放到哪里了? http://localhost/index.php/welcome/welcome
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
$this->load->view('welcome_message');
}
function index()
{
$this->load->view('welcome_message');
}
function index2()
{
$this->load->view('welcome_message');
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php
其实只要类名=action 的时候,,,构造函数自动执行,都会出现两个问题,好像不是index的问题。。
呵呵。。
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
//$this->load->view('welcome_message');
}
function index()
{
$this->load->view('welcome_message');
}
function index2()
{
$this->load->view('welcome_message');
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
http://localhost/index.php/welcome
执行1次。。嘿嘿 那就要改成 php5 的构造函数写法了。。。。。
页:
[1]
2