Base_url()是否在我的网址中添加了不必要的细分?

时间:2014-04-16 19:57:29

标签: php .htaccess codeigniter login base-url

我的base_url()在url中添加的位数多于应该的位数。我的设置有什么问题?我在config.php中设置了帮助器:

$autoload['helper'] = array('url');

我的base_url()设置为:index.php /

问题在于,当我激活此表单时:

<h1>sometimes haikus don't make sense refrigerator</h1>
<form action="<?php echo base_url(); ?>welcome/login_submit" method="post">
    <label>
        email:
        <input id="email" name="email" />
    </label>
    <label>
        password:
        <input type="password" id="password" name="password" />
    </label>
    <input type="submit" value="Log me in!" />
</form>

我第一次访问它时,我将输入:localhost / CIintranet /,然后添加base_url(),使其成为:localhost / CIintranet / index.php /

我正在尝试编写登录注销系统。因此,如果用户登录不正确,我希望它重定向回登录页面。以下是该部分控制器的代码:

public function login_submit() {
        $this->load->model('LoginChecker', 'users');
        //$this->load->view('login_submit');

        $match = $this->users->authenticate_user( $_POST['email'], $_POST['password'] );
        if( $match )
        {
            $this->load->view('login_submit');
            echo "User exists in database!";
        }
        else
        {
            $this->load->view('login_form');
            echo "<h1>Email or password is wrong, bretheren!</h1>";
        }
    }

但是当它重新加载login_form时,它会在url中添加另一部分而url会失败。所以进展是这样的:

页面加载到此网址:

localhost/CIintranet/

首次尝试失败(页面仍然正确加载):

localhost/CIintranet/index.php/welcome/login_submit

第二次尝试失败(页面无法加载):

localhost/CIintranet/index.php/welcome/index.php/welcome/login_submit 

我现在已经对此进行了一些研究,我注意到很多人都在谈论与此问题有关的htaccess文件,但似乎没有人具体提到修复它或如何配置{ {1}}这样才能正确处理这个问题。我试着查看文档,但也许我错过了一些东西。我找不到我想要的东西。

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您可以尝试将base_url设为/index.php/吗?所以前面也有正斜线?

如果失败,请尝试:http://localhost/CIintranet/index.php/

这通常是简单的事情!

答案 1 :(得分:0)

如果你使用......?

<?php echo form_open('welcome/login_submit') ?>
...
<?php echo form_close(); ?>

激活助手:表单