I'm writing a plugin for my editor to support the Yii framework.
To make this plugin work I need to find out 2 paths from index.php: the
framework and configuration paths.
The usual index.php (which is the entry point for Yii) looks like this:
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../../../../../usr/share/php-libs/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();
Basically I need to get list of required files and arguments for Yii::createWebApplication().
But the code here can be anything. Literally anything. So is it possible to run this file somehow up to Yii::createWebApplication() so I could find out where the application directory is and where the framework is?
You can use Yii::app()->basePath to get the root path of the application, and Yii::app()->baseUrl to get the relative URL for the application.
The Yii framework must to be in root htdocs of the Apache.
Related
I'm migrating a project over to phpstorm, but I'm not sure how to set this situation up correctly and can't find clear documentation.
My project structure is like this:
\projectroot <-- My phpstorm projects points at this directory
--\public_html <-- The web server points here
----\.user.ini <-- has include_path="C:\sites\projectroot\source"
----\index.php <-- and a few other php files
--\source <-- The folder containing real code
----\application.php <-- One example file
--\content
index.php includes files using require_once 'application.php' and within the source folder, files routinely do things like require_once 'model/user.php' to include other files within the source folder. How do I correctly get phpstorm to resolve these includes for this project only. I see that there is an includes section under Settings > PHP, but it's not clear if that is per project, and looks like that is maybe supposed to reference external libraries anyway.
i want to upload a web site the shared server.
structure
public_html
Yii(folder)
index.php (inside root folder)
I'm just getting this message "Server ERROR".please can someone tell me where is the problem or what should i change in my code to make it work.here is my index code:
<?php
// yii directory paths<br/>
$yii=dirname(__FILE__).'/yii/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following lines when in production mode<br/>
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message<br/>
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();
?>
If you could install a welcome yii application successfully then it is the problem of the index.php file in your app itself. One easy method is to copy the index.php file generated by your demo app and copy paste it in your original app. Make sure to keep the app in the same place where you kept your demo app.
Also, make sure that your vendor directories are there if you have used composer as well. Then check if the permissions are given correctly to the folders. Specifically the runtime and the assets folder. If in doubt you can simply chmod 777 on them.
If it is still giving error then there must be a problem with something you are using within your app which is probably missing something.
P.s please do express the error message properly so that we can get a better idea of the problem that you are facing.
I was just curious if Yii is supposed to be compiled into PHP or not. Is it possible to use Yii just by copying the Framework to a folder on the server and then including something (something as in one of the yii files- I am not sure how it works) in the scripts I wish to use the framework for?
(Noob when it comes to frameworks and usage)
Thanks,
Josh
I'll go with the line
Is it possible to use Yii just by
copying the Framework to a folder on
the server and then including
something
and answer yes :p Though, you should just follow webapp creation through yiic webapp like
so:
Download the yii (yii-someversion.tar.gz or what have you) distribution,
extract it somewhere (e.g. /opt/yii in *nix or C:/web/yii in windows.)
Now put that directory in your path ($PATH in *nix, or %PATH% in windows),
go to a shell / command prompt, change the directory to your
webserver's document root and do a yiic webapp <app folder name>
After answering a couple config question, you should have an look at the
index.php created there, you should have something like:
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();
and that's about it :p
Yii is a PHP framework and not an extension. You can just copy-paste it somewhere. Be sure to put the destination folder into your include path.
you just need to do it once to get an instance, and then you can copy this instance as much as you want, provided that the path of yii.php file in the index.php file is right, for me I usually copy the framework folder from the yii folder, paste it inside the instance in the folder "protected" and then change the path in index.php to "/protected/framework/yii.php"
To keep URLs working in version-controlled projects, I've been using $_SERVER['DOCUMENT_ROOT']. The problem is, I develop projects within a folder, so I get this:
$_SERVER['DOCUMENT_ROOT'] . '/folder/path/to/file.php'
When I go live, I generally simply want the following:
$_SERVER['DOCUMENT_ROOT'] . '/path/to/file.php'
I know there are bigger problems in the world than having to remove and add this folder name, but is there a way I can easily automate this? Can I somehow set my document root locally to include the folder I'm working in? Do I have a fundamental misunderstanding of the way things are working? Kind of new at this stuff, and looking to learn as much as possible and really grok the "why."
Thanks so much!
Instead of using $_SERVER['DOCUMENT_ROOT'], why not declare a constant which always holds the root of your web application?
<?php
define('ABSPATH', dirname(__FILE__));
Put the following code in a file located in the root folder of your application and include it on every page load.
Then, you can simply always do $path = ABSPATH . '/path/to/file.php'; regardless of if your local copy is in a sub-directory folder or not.
If your application already has a file which is included on every page load, you can simply drop the code above in that file and it will work.
Just note that you may have to add additional dirname() calls depending on where that file is located. Add one for each directory you pass from the root of your webapp.
For example, if your webapp is located in /webapp/ and your "global include" is located in /webapp/includes/framework/init.php, then the above code needs to be modified as such:
define('ABSPATH', dirname(dirname(dirname(__FILE__))));
ie.: 2 additional dirname() calls due to two additional folders from the webapp root (includes/framework)
Clarification
The code above is meant to be in one file, and one file only in your web application. That file needs to be included on each page load.
If you already have a file which is included before any processing (such as a configuration file or other), you may copy and paste that code in that file.
The number of dirname() calls depends on how deep the file you copied and pasted the
code in is relative to the root directory of your web application. For the examples above, assume the root of your web application is represented by ~.
If you copy-paste my code into ~/abspath.php, then you need one dirname() call.
If you copy-paste my code into ~/includes/abspath.php, then you need two dirname() calls.
If you copy-paste my code into ~/includes/config/abspath.php, then you need three dirname() calls. Now let's just say that's its final location.
In ~/index.php, you do the following:
<?php
require_once('includes/config/abspath.php');
and you have access to ABSPATH.
In ~/dir/someOtherPage.php you do the following:
<?php
require_once('../includes/config/abspath.php');
and you have access to ABSPATH.
This is why I'm saying that if you already have a file which is included on each page load, its simpler just to drop the above code in it. Just make sure you modify the amount of dirname() calls accordingly. Again, this code is meant to be in ONLY ONE FILE.
declare below line in any of root file (index.php)
$_SESSION["uploads_base_url"]=dirname(__FILE__);
and you can now use this in any of file where uploads needed.
echo $uploads_base_url=$_SESSION["uploads_base_url"];
I have found a little script which looks interesting, you can download the svn from google code at
http://code.google.com/p/streetwire/source/browse/
I am trying to set it up on my xampp localhost install, and there is little documentation, here are the first two lines of the config
// Paths
define('VHOST_DIR', '/data/vhost');
define('ROOT_DIR', VHOST_DIR . '/www.streetwire.org');
I have tried the following settings but it doesnt seem to work
// Paths
define('VHOST_DIR', 'C:/xampp/htdocs');
define('ROOT_DIR', VHOST_DIR . '/streetwirescript');
For anyone who has looked at the script, im not sure where to go for the 'start' page of the script either!!
Any thoughts on what should go into Vhost_dir?
Searching through the trunk (http://www.google.com/codesearch?q=root_dir+package%3Ahttp%3A%2F%2Fstreetwire.googlecode.com&origq=vhost_dir&btnG=Search+Trunk), VHOST_DIR is only used to define ROOT_DIR. It looks like all that matters is that ROOT_DIR points to the folder that the script is located in.
It's also possible that the script doesn't run on Windows.
It looks like you need to set /docs as the document root for this to work. E.g. index.php I assume you've seen INSTALL too.
Do you have error reporting on and set to maximum? There's a devsite constant in config that I assume gives error information too. What errors are you getting?