英文:
There is a error in my form_validation in code igniter 3 it has a red line under it when i hover my mouse on in it says unindentified property
问题
我已经将它添加到我的自动加载
$autoload['libraries'] = array('form_validation', 'session', 'pagination');
$autoload['helper'] = array('url', 'form', 'text');
这是我将在我的表单验证上使用set_rules函数的控制器代码。
public function register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|alpha');
}
尝试重新将form_validation添加到自动加载的库中
我真的不知道在这一点上该怎么办,目前是CodeIgniter的新手。
英文:
I already added it to my autoload
$autoload['libraries'] = array('form_validation','session', 'pagination');
$autoload['helper'] = array('url','form','text');
Here is the controller code where I am going to use the set_rules function on my form validation.
public function register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name','First Name','trim|required|alpha');
}
tried re-adding the form_validation to the autoload libraries
I don't really know what to do at this point currently a newbie at using code igniter.
答案1
得分: 0
你之所以会收到该错误是因为你的控制器及其父类在其源代码中没有form_validation
属性。
如果你查看CI_Controller
(你的控制器应该是扩展自CI_Controller
的)的源代码,你会发现这是正确的,但是CI_Controller
也允许你通过其load
属性加载库。
当你调用$this->load->library('form_validation')
时,这将在脚本执行期间为你请求的库(在本例中为form_validation
)在CI_Controller
上动态创建一个新的属性,然后你可以使用它。
但由于这个属性是动态添加的,不在源代码中,你的代码编辑器无法知道它,会认为你犯了一个错误并给出错误提示。
所以在这种情况下,你可以忽略这个错误,你的代码应该可以正常工作!
英文:
You're getting that error because your controller and its parent classes do not have a form_validation
property in their source code.
If you look at the source code for CI_Controller
(your controller should be extending CI_Controller
) you can see that this is true, but CI_Controller
also allows you to load libraries via its load
property.
When you call $this->load->library('form_validation')
this then (during script execution) creates a new property on CI_Controller
for the library you've requested (form_validation
in this case), which you can then use.
But since this property is added dynamically and is not in the source code, your code editor can't know about it, thinks you're making a mistake and gives you the error.
So you can ignore the error in this case, your code should work!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论