我自己的图书馆和检查表格有问题。代码点火器
我有一个问题,一切正常,但后来我尝试将我的函数放入我自己的库中(以在不同的控制器中使用它们),但它不起作用。
我有这样的 SIGNUP 控制器:
$this->load->library('Check_functions');
// We check the form
$return_verif_form_signup = $this->check_functions->verif_form_signup($language);
它调用我的库 Check_functions:
class Check_functions {
public function verif_form_signup($language) {
if ($this->input->post()){
// Verification rules
$this->form_validation->set_rules('name', 'lang:name', 'trim|required|xss_clean');
....
if ($this->form_validation->run($this)) {
extract($_POST);
...
...
}
但我收到错误: 致命错误:在非对象上调用成员函数 post()
有谁知道我如何修复它?
谢谢!
编辑:
我发现了问题,回调函数没有被调用。如果我将 callback_free_email
替换为 REQUIRED 并且没有输入电子邮件,则我的表单不会提交,所以没关系。 但如果我有以下代码,我的表单总是会提交。所以回调函数永远不会被调用...
这是我的代码(我正在使用HMVC):
class Check_functions {
private $CI;
public function __construct(){
$this->CI =& get_instance();
}
public function verif_form_signup($language) {
if ($this->CI->input->post()){
$this->CI->form_validation->set_rules('name', 'lang:field_name', 'trim|required|min_length[3]|max_length[25]|xss_clean');
$this->CI->form_validation->set_rules('email_signup', 'lang:field_email', 'callback_free_email');
...//other rules
if ($this->CI->form_validation->run($this->CI)) {
.....
}
}
}
public function free_email($str) {
return FALSE; // I have temporarly set that so I see if my function is called
}
}
我有一个名为MY_Form_validation.php的文件,如下所示:http://codeigniter.com/forums/viewthread/143057/#769347
class MY_Form_validation extends CI_Form_validation{
function run($module = '', $group = ''){
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
我真的不知道出了什么问题......为什么我的回调函数没有被调用?
感谢您的帮助!
I have a problem, everything was working but then I tried to put my functions in my own libraries (to use them in different controllers) and it doesn't work.
I have SIGNUP controller with this:
$this->load->library('Check_functions');
// We check the form
$return_verif_form_signup = $this->check_functions->verif_form_signup($language);
which calls my librarie Check_functions:
class Check_functions {
public function verif_form_signup($language) {
if ($this->input->post()){
// Verification rules
$this->form_validation->set_rules('name', 'lang:name', 'trim|required|xss_clean');
....
if ($this->form_validation->run($this)) {
extract($_POST);
...
...
}
But I get the error:
Fatal error: Call to a member function post() on a non-object
Does anyone know how I could fix it?
thanks!
EDIT:
I have found the problem, the callback function is not called. If I replace callback_free_email
by REQUIRED and I don't enter an email, my form is not submitted, so it's okay.
But if I have the following code, my form is always submitted. So the callback function is never called...
This is my code (i'm using HMVC):
class Check_functions {
private $CI;
public function __construct(){
$this->CI =& get_instance();
}
public function verif_form_signup($language) {
if ($this->CI->input->post()){
$this->CI->form_validation->set_rules('name', 'lang:field_name', 'trim|required|min_length[3]|max_length[25]|xss_clean');
$this->CI->form_validation->set_rules('email_signup', 'lang:field_email', 'callback_free_email');
...//other rules
if ($this->CI->form_validation->run($this->CI)) {
.....
}
}
}
public function free_email($str) {
return FALSE; // I have temporarly set that so I see if my function is called
}
}
I have a file called MY_Form_validation.php as suggested here: http://codeigniter.com/forums/viewthread/143057/#769347
class MY_Form_validation extends CI_Form_validation{
function run($module = '', $group = ''){
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
I really don't know what's wrong... why my callback function is not called?
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您编写库时,您必须像这样手动获取 Codeigniter 实例
,然后您将使用
$CI
(通常使用$this
与加载的 codeigniter 资源进行交互) ...
而不是
您在此处编写
文档进行解释 http://codeigniter.com/user_guide/general/creating_libraries.html
示例库结构
when you are writing libraries, you have to manually grab the Codeigniter instance like this
then you would use
$CI
where you would normally use$this
to interact with loaded codeigniter resourcesso...
instead of
you would write
Docs explain it here http://codeigniter.com/user_guide/general/creating_libraries.html
EXAMPLE LIBRARY STRUCTURE
我终于找到了一个解决方法,我没有在规则中使用回调,而是稍后进行测试并调用验证函数。
就这样运作得很好。
感谢您的帮助!
I finally found a workaround, instead of using the callback in my rule, I do a test later and call a verification function.
It’s works well like that.
Thanks for your help!