Codeigniter没有显示validation_errors()

时间:2014-04-03 01:18:55

标签: php .htaccess codeigniter

解决方案:我在VPS上使用了WAMP服务器。问题是重写模块没有加载到apache设置中。我通过进入我的apache文件夹/ conf / http.conf并删除此行前面的#标签来修复此问题:LoadModule rewrite_module modules / mod_rewrite.so。我重新启动了apache并且工作正常。

编辑:即使我输入了电子邮件和密码,它也没有运行。我似乎根本无法运行form_validation。

编辑2:还发现我无法回复$ this-> input-> post('email');在函数login_validation中。

编辑3:我回应了$ this-> output-> enable_profiler();它说我没有发送任何帖子数据。我的.htaccess可能会对帖子做些什么吗?

我正在使用codeigniter创建登录/注册系统。我让它在localhost上工作但是当我把它移动到我的主机时必定会发生一些事情。

我在autoload.php中自动加载表单:

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

这是我在类Main files controllers / main.php中的验证代码:

public function login_validation(){

    $this->load->library('form_validation');

    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required|md5');

    if($this->form_validation->run()){
        //NO VALIDATION ERRORS
    }else{
        echo 'Errors:<br />';
        echo validation_errors();
    }
}

我的表格:

<?php 
echo form_open('main/login_validation');

$property_type = array('class' => 'bar left', 'value' => 'E-Mail', 'name' => 'email');
echo form_input($property_type);

$property_type = array('class' => 'bar right', 'value' => 'Password', 'name' => 'password');
echo form_password($property_type);

$property_type = array('class' => 'buttonone', 'value' => 'Login', 'name' => 'login_submit');
echo form_submit($property_type);

echo form_close(); 
?>

当我没有在表格中输入任何内容时,它应该显示电子邮件和密码是必需的。它只说错误:但它不会显示验证错误。

当我将其上传到我的主人时,我还必须更改为另一个.htaccess。

这是我的新htaccess:

  <IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
</IfModule>

这是我原来的.htaccess:

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]    

2 个答案:

答案 0 :(得分:0)

只需检查if条件并将表单错误函数放入查看页面

public function login_validation(){

    $this->load->library('form_validation');

    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required|md5');

      if ($this->form_validation->run($this) !== FALSE) //write like this if condition
      { 
        //NO VALIDATION ERRORS
    }else{
        echo 'Errors:<br />';
        echo validation_errors();
    }
}

您的视图页面已放入此

<?php echo validation_errors(); ?>

更多参考此http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

答案 1 :(得分:0)

我在我的VPS上使用了WAMP服务器。问题是重写模块没有加载到apache设置中。我通过进入我的apache文件夹/ conf / http.conf并删除此行前面的#标签来修复此问题:LoadModule rewrite_module modules / mod_rewrite.so。我重新启动了apache并且它运行了。