普通网友 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退