代码点火器控制器功能问题


codeigniter controller function issue

我是Codeigniter编程的新手。我通过简单地编辑我的默认控制器欢迎来启动CI。我在控制器中添加了一个函数,点击提交按钮即可调用该函数。我没有在默认框架或配置文件中做任何修改。但是单击提交按钮后,应用程序将返回404响应。未找到在此服务器上找不到请求的URL/login/welcome/main。位于localhost端口80的Apache/2.2.14(Ubuntu)服务器

主要功能是我在欢迎控制器中写的内容。谁能告诉我出了什么问题吗。我的Codeigniter版本是2.1.0。我重新安装了Apache和PHP。但没用了。控制器的代码和下面的欢迎页面。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL);
class Welcome extends CI_Controller {
    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('login_page');
        //$this->load->view('phpinfo');
    }
    public function main()
    {
    $this->load->view('phpinfo');
    }

欢迎页面是

<div id="container">
<h1>Ignitor</h1>
<div id="body">
    <code>Please Login to continue. </code>

    <div id="login_form">
    <?php echo form_open(base_url().'welcome/main');?>
    <ul>
    <li>
    <label>Username </label>
    <?php echo form_input(array('id' => 'username', 'name' => 'Username'));?>
    </li>

    <li>
    <label>Password </label>
    <?php echo form_password(array('id' => 'password', 'name' => 'Password'));?>
    </li>

    <li> <?php echo form_submit(array('id'=>'submit'),'Let me in' )?></li>
    </ul>
    <?php echo form_close();?>
    */ 

老兄。。

class Welcome extends CI_Controller {
    public function index()
    {
        // echo 'Index';
        $this->load->view('welcome');
        // Then save the file in your application/views/welcome.php
        // http://yours.com/index.php/welcome
        // Or http://yours.com/welcome <-- With htaccess
    }
    public function main()
    {
        // echo 'Index';
        $this->load->view('main');
        // Then save the file in your application/views/main.php
        // http://yours.com/index.php/welcome/main
        // Or http://yours.com/welcome/main <-- With htaccess
    }
}

默认情况下,index.php文件将包含在您的URL 中

通过使用.htaccess文件和一些简单的规则,您可以很容易地删除此文件。下面是这样一个文件的例子,使用"负"方法,除指定项目外,所有内容都被重定向:

RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

您设置好.htaccess文件了吗?应该是这样的:

RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

您正在跳过URL中的index.php,这意味着您希望有一个.htaccess文件将请求路由到CodeIgniters main index.php.

使用URL/login/index.php/welcome/main检查.htaccess文件是否有错误或不存在。如果您将其所在的目录重命名或移动为"登录",则可能忘记更新该目录。

"login"目录中的.htaccess应该类似于-

RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /login/index.php/$1 [L]

如果它正在查找主index.php,并且错误是由于视图/模型/控制器命名问题引起的,那么您将从CodeIgniter而不是Apache获得404。

您是否正确命名了welcomepage视图文件?换句话说,您的控制器要求将login_page_view.php(或者至少我认为这是默认的文件名约定)放在基于代码行的视图文件夹中:

$this->load->view('login_page');