普通网友 2018-07-14 16:15
浏览 102

CodeIgniter env基于MY_类扩展

I'm working on a CodeIgniter 3.1.4 project and am aware that I can use MY_ prefixed library classes to extend the system libraries.

This is great and works as expected, but I'd like to be able to determine the class being used dependant on either the current environment, or by DotEnv values (I've already got a DotEnv library working fine).

The production site uses the servers 'sendmail' to send email, I would like to be able to use MailGun (or another) in development, allowing me to overriding the 'to' value just before sending to allow for safe development utilising a production like dataset.

Much like is able to be done in Laravel where you can use .env's MAIL_DRIVER=mailgun and MAIL_TO_ADDRESS=x@y.com to force all outbound mail to one address for development.

I'm sure it must be possible, but my lack of experience with CI and where I should be implementing this into the framework is letting me down.

  • 写回答

1条回答 默认 最新

  • ds3016 2018-07-15 20:33
    关注

    The answer is actually in the links that Vickel sent. You can override your configuration files per domain/environment and you can therefore change the MY_ prefix to YOUR_ prefix in the different config.php file.

    How you do this (quoted but tweaked):

    Create the directory application/config/not_my_environment/

    Copy your existing config.php into the above directory

    Edit application/config/not_my_environment/config.php so it contains your production settings

    Set the ENVIRONMENT constant based on an htaccess SetEnv variable (I have just posted a very similar answer here: Maintain the same project within multiple sub-domains) which then allows you to vary your files per domain.

    Once you are running off a custom per-deployment set of configuration files you can set the prefix to be whatever you like and therefore have multiple MY_, YOUR_, ANY_ prefix based classes override the CI defaults.

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能