代码点火器和配置文件中的自定义库?
我在代码点火器中有一个库,看起来像 class MyClass($options = array())
文件是 Myclass.php
我有一个文件 (config/ Myclass.php
)看起来像
$Myclass = array(
'something' => 'value',
'another' => 'value'
);
我认为在初始化我的类时应该传递 $Myclass
数组,但显然不是?
我需要做什么来修复它?
I have a library in code igniter that looks like class MyClass($options = array())
The file is Myclass.php
I have a file (config/Myclass.php
) that looks like
$Myclass = array(
'something' => 'value',
'another' => 'value'
);
Which I thought should pass the $Myclass
array in when I initialize my class, but apparently not?
What do I need to do to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊,我找到了答案,
配置文件中的数组必须名为
$config
。文件名还必须是库文件名的小写表示形式。
例如
LIB文件:
Somelibrary.php
LIB 内容:
class Somelibrary($options = array()){...
配置文件:
somelibrary.php
配置内容:
$config = array('something' => 'value');
AH I found the answer,
The array inside your config file must be called
$config
.The name of the file must also be a lower case representation of the library file name.
e.g
LIB FILE:
Somelibrary.php
LIB CONTENTS:
class Somelibrary($options = array()){...
CONF FILE:
somelibrary.php
CONF CONTENTS:
$config = array('something' => 'value');
通常的工作方式是传入一组您希望覆盖的选项,或者不传入任何内容以使用默认值。
老实说,如果没有充分的理由,我不会在配置中创建您自己的文件;相反,只需将默认值放入类定义中,然后在构造函数中覆盖:
The way this usually works is that you pass in an array of options you wish to override, or pass in nothing to use the defaults.
Honestly, I wouldn't create your own file in config without a good reason; instead, just put the defaults in your class definition, and then override in your constructor:
快进到 2013 年,仍然有人遇到这个问题。所以我的情况是一样的,但略有不同,所以我想我应该尝试拯救别人一些时间。
我在我的扩展类之后命名我的配置文件,这是错误的。 配置文件应该始终是 form_validation.php,(这是因为最终它会被传递给 CI_Form_validation 类,这就是它所期望的)
感谢上面回答这个问题的人,我意识到我必须将配置传递给父类,并使用 codeigniter v2.1.3 执行如下操作:
Fast-forward to 2013, someone is still having problems with this. So my situation was the same but slightly different, so I thought I'd try to save someone else some time.
I was naming my config file after my extended class, that was wrong. The Config file should always be form_validation.php, (this is because eventually it is handed to the CI_Form_validation class and that's what it expects)
Thanks to the folks who answered this question above, I realized that I had to pass the config to the parent class and using codeigniter v2.1.3 I did it as follows: