Where YII_DEBUG can be defined? - yii2

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.

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.

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.

Related

In PhpStorm new file menu, there is no .php or php class option

In PhpStorm, when i want to create a new file, there used to be three options for php at the top of the list. new PHP file, new PHP Class, and something else.
Now there is no option for php. there is just 'file', 'directory', 'new scratch file' and then html/css/etc file types.
Problem solved. for anyone having this question in the future, you should know that PhpStorm has the above behavior when indexing the project, which usually happens every time you open a project.
but in my case, something(I don't know what), had caused to add "." to the list of paths to be indexed, making PhpStorm index the whole home folder, and naturally, it took a lot of time.

Not able to make calls to mod_roster_odbc functions

I tried to use my own custom roster by integrating mod_roster_odbc. I changed the config file too (commented out mod_roster and make a new entry for mod_roster_odbc). After running with this setup, mod_roster_odbc module is getting started ( I put some logs to in start function, those I can see). But none of other function is not getting called as I alter presence or logged out/logged in.
Please help to identify where I am making the mistake.
I think I know the answer to this. many websites tell you to use mod_roster_odbc.erl to create your own rostering. I believe thats your problem. Many of the functions are merged into mod_roster.erl file itself. I dont think this is mentioned anywhere.
So what you need to do is in ejabberd.cfg enable mod_roster_odbc but dont remove the mod_roster.erl file with the odbc file. This file will take care.
Finally you need to create a rosterusers table (or something like it) so that ejabber can query for friend list. After these changes, just restart ejabber server and you should be good to go. hope this helps.

Timthumb Could not find the internal image you specified

I am using Timthumb to reisze pictures in my wordpress blog.
It's woirking fine on my local machine but when upload it on remote server Timthumb return me the following error:
Could not find the internal image you specified.
And a 400 Bad request in browser console.
How to fix this? i've been told that it might depend from server path configuration.
Timthumb version i am using is: 2.8.10
I just had that error and it was because it was looking for the file in the wrong place in the filesystem. Enable debugging and set it to level 3. Open the page where it says this error. Download the error log (same directory as the script). You'll see all the paths it tries. Output dirname(__FILE__) from just about anywhere. You'll see the real path it needs. Add it to the timthumb-config.php as
$_SERVER['DOCUMENT_ROOT'] = '/home/username/public_html';
Just as an example I had to do this (wrap in php tag). Previously it was using something with /bin/usr/htdocs in it, and that's too much detail!
Around line 850 in the getLocalImagePath funcion, add this:
$src = str_replace ( "~username/" , "" , $src );
This is optional, replace username with something else.
Another case where you are using some htaccess magic so the images are accessed like /files/2012/02 rather than /wp-content/uploads/2012/02 TimThumb would work well if it'd treat this as an external URL... But it treats it as internal and it won't find the images so set a docroot accordingly and you might need to use the replace hack mentioned previously.
I have some tweaks on .htaccess to hide the fact that I'm using Wordpress.
On timthumb 2.8.11.
After
$this->localImage = $this->getLocalImagePath($this->src);
i'v hadded this line of code
$this->src = str_replace('/file/', '/wp-content/uploads/', $this->src);
The /file/ in the normal WPway should be /wp-content/uploads/.

create arbitrary values in php.ini

I would like to put some of my app config data in php.ini
I tried just to add new values there and then get them with ini_get
I get nothing displayed.
Do I need to define new entries in an extension?
I know I can create a config file/ini file and easily parse it with PHP, But I want to avoid that.
I do that as I assume it is being loaded once per process.
I do not give here the big big picture, as I want to keep it as much as possible only a technical question, sadly, this platform does not allow debates.
I do need it inside the php.ini
Have you looked at get_cfg_var( config_var )?
http://www.php.net/manual/en/function.get-cfg-var.php
I believe this is for retrieving custom variables from e.g. the servers php.ini file
Don't use php.ini to configure your application, it's not the right place (as the name says, it's intended to configure php, not any application using it).
If you want to use ini files for your application's configuration, have a look at parse_ini_file()

Best way/practice to ensure links are going to proper location when not on root of domain?

I've been wondering this for a while now, but what is the best way to ensure that in a web app (RoR, Sinatra, PHP, anything) that when you are creating links (either generating with a method, or writing in by hand) that they go to the proper place whether you are on the root of a domain or not: http://www.example.com/ or http://www.example.com/this/is/where/the/app/is/
My thoughts are get the end-user to specify a document root somewhere in the config of your app, and use that, however I'm trying to think of a nice way to do it without the end-user having to configure anything.
Edit: By end-user, I mean the person setting up the application on a server.
Edit: I can use the beginning '/' to always get the link relative to the domain, but the problem is what if the app itself is not at the root, but some place like http://www.example.com/this/is/where/the/app/is/ so i want to say gen_link('/') and have it return /this/is/where/the/app/is/ or gen_link('/some/thing') and return /this/is/where/the/app/is/some/thing
How about trying to set the base element in the head of you html layout?
First, get the URL, eg. in a way Ilya suggests (if PHP is OK for you). After that you can use the base tag as follows:
<base href="<?= $full_site_url ?>" />
That will set the default URL for all the links and the browser will prepend it to every relative link on the page.
First of all you need to route all your urls through some kind of url re-writer function.
So you no longer do:
Foo
But instead something like:
Foo
All the web frameworks out there have a function like this. While they usually do all kinds of magic in there (to do with MVC controller paths and views and what not), at the end of the function (conceptually) they all prepend your url with a "root" (eg "/this/is/where/the/app/is/"), so as to allow you to create urls in your application that are independent of a hard-coded base path.
RoR uses a configuration directive called "relative_url_root".
Symfony (php) uses a configuration directive also called "relative_url_root".
CakePHP uses a configuration directive called "WEBROOT_DIR".
In cases where these frameworks are running on Apache, this value is often calculated dynamically (if you haven't set it explicitly). On other webservers the environment variables are often not available or are incorrect so this value cannot be determined consistently.
ilya's answer is a good one, but I think a simpler way to do this is just to precede all your links with a leading "/". This will ensure that they are always relative to the root of the domain:
Something <!-- Always links to www.domain.com/some/thing -->
Something <!-- Acutal destination depends current path -->
You can determine everything you need yourself, no need for configs.
Here’s a PHP example (let’s say index.php is your script name):
<?
$folder_on_server = substr ($_SERVER['PHP_SELF'], 0, strpos ($_SERVER['PHP_SELF'], '/index.php'));
$server_name = $_SERVER['SERVER_NAME'];
if (80 != $_SERVER['SERVER_PORT']) {
$server_name .= ':'. $_SERVER['SERVER_PORT'];
}
$full_site_url = 'http://'. $server_name . $folder_on_server;
?>
Now, you can always make a link like this:
Something
See also discussion in comments.