PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 9, 2022

[FIXED] Yii 1 Console Application Environment Variables

 January 09, 2022     console-application, environment-variables, php, yii     No comments   

Issue

For a Yii 1 web application, I am using the symfony/dotenv library to read and load environment variables from a .env file. To do this, I added a code in the index.php file,

require 'vendor/autoload.php'; //autoload for composer

if(file_exists('/path/to/.env')){
    $dotenv = new Symfony\Component\Dotenv\Dotenv();
    $dotenv->load(__DIR__.'/path/to/.env');
}
else{
   // Missing .env file
   exit;
}

This works well with the web application. However, for Yii console applications, this does not work because index.php is not being loaded. Can this be done inside the console.php file? How?


Solution

For console application you can do the same in protected/yiic.php. This file is used for bootstrap when you call ./yiic, in similar way as index.php is loaded on web request.



Answered By - rob006
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing