简体   繁体   English

Codeigniter不显示validation_errors()

[英]Codeigniter not displaying validation_errors()

SOLUTION: I used WAMP server on my VPS. 解决方案:我在VPS上使用了WAMP服务器。 The problem was the rewrite module was not loaded in the apache settings. 问题是apache设置中未加载重写模块。 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. 我通过进入apache文件夹/conf/http.conf并删除以下行的主题标签来解决此问题:LoadModule rewrite_module modules / mod_rewrite.so。 I restarted apache and it worked. 我重新启动了apache并成功了。

EDIT: It's not running even tho i input an email and password. 编辑:即使我输入电子邮件和密码也无法运行。 I am not being able to run the form_validation at all it seems. 我似乎完全无法运行form_validation。

EDIT 2: Also found out i can't echo $this->input->post('email'); 编辑2:还发现我无法回显$ this-> input-> post('email'); in the function login_validation. 在函数login_validation中。

EDIT 3: I echoed out $this->output->enable_profiler(); 编辑3:我回显了$ this-> output-> enable_profiler(); and it said i sent no post data. 它说我没有发过帖子数据。 Is it possible that my .htaccess is doing something with the posting? 我的.htaccess是否有可能在发布内容?

i'm creating a login / registration system using codeigniter. 我正在使用codeigniter创建一个登录/注册系统。 I got it to work on localhost but something must have happened when i moved it to my host. 我可以在localhost上运行它,但是将其移到主机时一定发生了某些情况。

I autoload form in my autoload.php: 我在autoload.php中自动加载表格:

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

This is my validation code in class Main file controllers/main.php: 这是我在Main File 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();
    }
}

My form: 我的表格:

<?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(); 
?>

When i dont type in anything in the form it should display Email and password is required. 当我不输入任何形式的信息时,它应该显示电子邮件和密码。 It only says Errors:. 它只说错误:。 But it does not display the validation errors. 但是它不显示验证错误。

I also had to change to another .htaccess when i uploaded it to my host. 将其上传到主机时,我还必须更改为另一个.htaccess。

This is my new 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>

This is my old .htaccess: 这是我的旧.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]    

just check the if condition and put form error function in to view page 只需检查条件,然后将表单错误功能放入查看页面

public function login_validation(){ 公共功能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();
    }
}

your view page put in to this 您的视图页面放入此

<?php echo validation_errors(); ?>

more refer this http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html 有关更多信息,请参见http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

I used WAMP server on my VPS. 我在VPS上使用了WAMP服务器。 The problem was the rewrite module was not loaded in the apache settings. 问题是apache设置中未加载重写模块。 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. 我通过进入apache文件夹/conf/http.conf并删除以下行的主题标签来解决此问题:LoadModule rewrite_module modules / mod_rewrite.so。 I restarted apache and it worked. 我重新启动了apache并成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM