Home Articles

Codeigniter没有显示validation_errors()

Asked
Viewed 526 times
0

SOLUTION: I used WAMP server on my VPS. The problem was the rewrite module was not loaded in the apache settings. I fixed this by going into my apache folder/conf/http.conf and removing the hashtag infront of this line: LoadModule rewrite_module modules/mod_rewrite.so. I restarted apache and it worked.

编辑:即使我输入了电子邮件和密码,它也没有运行 . 我似乎根本无法运行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:
'; 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 Answers

  • 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:
    '; echo validation_errors(); } }

    您的视图页面放入此页面

    <?php echo validation_errors(); ?>
    

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

  • 0

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

Related