Ivan Romanov
Ivan Romanov

Reputation: 1228

Where YII_DEBUG can be defined?

By default Yii2 generates file web/index.php with defined('YII_DEBUG') or define('YII_DEBUG', true); line. It's entry point of any page on site. And this the first line of a code. So checking for defined YII_DEBUG seems meaningless. I suppose this constant can be defined in something else place. But can't find where to do it.

In my personal case I have a local version of site and want to enable this constand for debugging purposes but don't want to change web/index.php. This file is under VCS (git) and I don't want to accidentally enabled debug in production.

StackOverflow has allready similar question. But it targeted on other sense and didn't give answer on my question. So I just created a new question.

Upvotes: 0

Views: 409

Answers (2)

Michal Hynčica
Michal Hynčica

Reputation: 6144

Even if the index.php is default entry point for Yii app, you can still create your own entry point, include the index.php in it and set web server to use that file instead of index.php.

For example you can create custom-entry.php like this:

<?php

define('YII_DEBUG', false);

// do something ...

require index.php;

Or you can define YII_DEBUG in some script that is run at start of each request by auto_prepend_file directive.

But those are not exactly best options how to deal with your case. In your case I would suggest to simply set your versioning system to ignore local changes of index.php file. For example if you are using GIT you can use skip-worktree flag to do that. I don't know CVS much so I'm not sure how exactly it is done with that.

Upvotes: 1

Bizley
Bizley

Reputation: 18021

Yii does it like that

defined('YII_DEBUG') or define('YII_DEBUG', true);

which means that if it's not defined already - define it.

This is a proper place to define it. The above statement is just in case somehow you got this already defined by any mean which Yii will honor.

Upvotes: 0

Related Questions