php CodeIgniter - 无法访问与您的字段名称密码相对应的错误消息。(pword_check)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32665715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter - Unable to access an error message corresponding to your field name Password.(pword_check)
提问by Shivam Gupta
I am a new to codeIgniter and I just got stuck in the very beginning. I am using HMVC extention and while validating I am getting the following error:
我是 codeIgniter 的新手,我刚开始就陷入困境。我正在使用 HMVC 扩展,在验证时出现以下错误:
Unable to access an error message corresponding to your field name Password.(pword_check)
无法访问与您的字段名称密码相对应的错误消息。(pword_check)
any help would be greatly appreciated
任何帮助将不胜感激
Code:
代码:
public function submit()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|max_length[30]|xss_clean');
$this->form_validation->set_rules('pword', 'Password', 'required|max_length[30]|callback_pword_check|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->login();
}
else
{
echo 'Success'; die();
}
}
public function pword_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message('pword_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
回答by Saty
xss_clean is no longer part of form validation in Codeingitore 3
xss_clean 不再是 Codeingitore 3 中表单验证的一部分
Just remove xss_clean
from your validation roul
只需xss_clean
从您的验证名单中删除
$this->form_validation->set_rules('pword', 'Password', 'required|max_length[30]|callback_pword_check');
If you really, really need to apply that rule, you should now also load the Security Helper, which contains xss_clean()
as a regular function and therefore can be also used as a validation rule.
如果您真的,真的需要应用该规则,您现在还应该加载安全助手,它包含xss_clean()
一个常规函数,因此也可以用作验证规则。
go to application/config/autoload.php :
去 application/config/autoload.php :
$autoload['helper'] = array('security');
Or, before your form validation
或者,在您的表单验证之前
$this->load->helper('security');
回答by Shivam Gupta
Hello Guys I found the solution for working with call_backs in hmvc codeIgniter. I would like to post the solution for others.
大家好,我找到了在 hmvc codeIgniter 中使用 call_backs 的解决方案。我想为其他人发布解决方案。
Solution:
解决方案:
1. Create MY_Form_validation.php file in libraries folder and paste following code in it.
1. 在libraries 文件夹中创建MY_Form_validation.php 文件并将以下代码粘贴到其中。
if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation
{
function run($module = '', $group = '')
{
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation
{
function run($module = '', $group = '')
{
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
- And change
if ($this->form_validation->run() == FALSE)
toif ($this->form_validation->run($this) == FALSE)
thats all folks..
- 并更改
if ($this->form_validation->run() == FALSE)
为if ($this->form_validation->run($this) == FALSE)
所有人..
回答by Bang Andre
public function pword_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message( __FUNCTION__ , 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
// Its working well
// 它运行良好
回答by Jomar Gregorio
For future searches. There are two 3things you need to check when this error shows.
供以后搜索。有两个3件事情你需要检查时出现此错误。
Check the name of the callback function if it is the same with the
$this->form_validation->set_rules('pword', 'Password', 'required|max_length[30]|callback_pword_check
public function pword_check($str){ if ($str == 'test'){ $this->form_validation->set_message('pword_check', 'The %s field can not be the word "test"'); return FALSE; } else{ return TRUE; } }
*public function pword_check($str){
*set_message('pword_check', 'The %s field...
In codeigniter 2.X you can do this
$this->form_validation->run($this) == TRUE
In 3.x it should be like this
$this->form_validation->run() == TRUE
and you need to add this two line of codes on __construct()
function __construct(){ parent::__construct(); $this->load->library('form_validation'); $this->form_validation->CI =& $this; }
Add this file on your application/libraries/MY_Form_validation.php
<?php class MY_Form_validation extends CI_Form_validation{ public $CI; }
检查回调函数的名称是否与
$这- > form_validation-> set_rules(必需'PWORD', '密码',” | MAX_LENGTH [30] | callback_ pword_check
public function pword_check($str){ if ($str == 'test'){ $this->form_validation->set_message('pword_check', 'The %s field can not be the word "test"'); return FALSE; } else{ return TRUE; } }
*公共函数pword_check($str){
*set_message(' pword_check', '%s 字段...
在 codeigniter 2.X 你可以这样做
$this->form_validation->run($this) == TRUE
在 3.x 中应该是这样的
$this->form_validation->run() == TRUE
你需要在 __construct() 上添加这两行代码
function __construct(){ parent::__construct(); $this->load->library('form_validation'); $this->form_validation->CI =& $this; }
将此文件添加到您的应用程序/库/ MY_Form_validation.php
<?php class MY_Form_validation extends CI_Form_validation{ public $CI; }
Cheers! See https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src/f77a3fc9a6fd?at=codeigniter-3.x
https://www.youtube.com/watch?v=pp4Y_bIhASY&list=PLBEpR3pmwCayNcTCUWlUToK4qIQfFQCCm&index=8
https://www.youtube.com/watch?v=pp4Y_bIhASY&list=PLBEpR3pmwCayNcTCUWlUToK4qIQfFQCCm&index=8
For reference.
以供参考。
回答by Aditya A
before going to the helper security check on the file application/config/autoload.php
add form_validation in librariies
在对文件进行辅助安全检查之前,在库中application/config/autoload.php
添加 form_validation
$autoload['libraries'] = array('form_validation');
and don't forget to add security
并且不要忘记添加安全性
$autoload['helper'] = array('security');
try it
尝试一下
回答by Roberto D. Garcia
The reason for this error is you didn't loaded the security helper the following is the way enable security helper with autoload.php in config folder or you can directly load the helper as mentioned last line of this post
出现此错误的原因是您没有加载安全助手,以下是在 config 文件夹中使用 autoload.php 启用安全助手的方法,或者您可以直接加载助手,如本文最后一行所述
And if, despite everything, you really need it, go to application/config/autoload.php :
如果,尽管如此,您确实需要它,请转到 application/config/autoload.php :
$autoload['helper'] = array('security'); Or, before your form validation $this->load->helper('security');
$autoload['helper'] = array('security'); 或者,在您的表单验证之前 $this->load->helper('security');