【问题标题】:Codeigniter - getting array from form validation config fileCodeigniter - 从表单验证配置文件中获取数组
【发布时间】:2011-12-16 11:47:04
【问题描述】:

如何从控制器中的表单验证配置文件中获取数组?

application/config/form_validation.php

我有一个想法,将我的表单验证数组保存到 config.php,然后在 form_validation.php 中引用它。然后我将能够在控制器中获取它,并能够在验证中使用它。

有没有更好(直接)的方法?

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    试试

    $this->config->load("form_validation");
    

    然后

    $this->config->item($key_name);
    

    文档:- http://ellislab.com/codeigniter/user_guide/libraries/config.html

    【讨论】:

    • 我是 CodeIgniter 世界的新手,所以我对 $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).
    • 它不起作用,这只会返回配置项,而不是来自 config>form_validation.php 的数组
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 2015-10-12
    • 2013-01-17
    • 1970-01-01
    • 2017-07-16
    相关资源
    最近更新 更多