【发布时间】:2011-12-16 11:47:04
【问题描述】:
如何从控制器中的表单验证配置文件中获取数组?
application/config/form_validation.php
我有一个想法,将我的表单验证数组保存到 config.php,然后在 form_validation.php 中引用它。然后我将能够在控制器中获取它,并能够在验证中使用它。
有没有更好(直接)的方法?
【问题讨论】:
标签: php codeigniter
如何从控制器中的表单验证配置文件中获取数组?
application/config/form_validation.php
我有一个想法,将我的表单验证数组保存到 config.php,然后在 form_validation.php 中引用它。然后我将能够在控制器中获取它,并能够在验证中使用它。
有没有更好(直接)的方法?
【问题讨论】:
标签: php codeigniter
试试
$this->config->load("form_validation");
然后
$this->config->item($key_name);
文档:- http://ellislab.com/codeigniter/user_guide/libraries/config.html
【讨论】:
$config[] 变量感到困惑。我认为当我执行$this->config->load("form_validation"); 时,来自 config.php 的$config[] 将覆盖来自 form_validation.php 文件的$config[]。我错了,对吧? :)
Note: If you do create your own config files use the same format as the primary one, storing your items in an array called $config. CodeIgniter will intelligently manage these files so there will be no conflict even though the array has the same name (assuming an array index is not named the same as another).