普通网友 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 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏