I've decided that rather than have a copy of the Zend Framework in each application's directory, I'd like to keep it on one location on the server, with the one copy used by all my websites. However, I'd like my app's custom classes to still be within the application folder. So a folder structure a bit like this:
webroot
|...library
| |......Zend
|
|...app1
| |.....Library
| |.......App1
|
|...app2
|.....Library
|.......App2
How can I get Zend Loader to automatically find the classes in App1 and App2? (preferably by just changing something in application.ini or bootstrap.php)
You can create a single library directory, with symlinks to the actual live shared code:
webroot/library/Zend -> /path/to/Zend/library/Zend
webroot/library/App1 -> /path/to/App1/library/App1
webroot/library/App2 -> /path/to/App2/library/App2
Then, you only need webroot/library in your path.
To handle version updates, you can simply change the symlink to point to a new install:
webroot/library/Zend -> /path/to/Zend-test/library/Zend
The Zend Loader will use your php include_path to find files to load.
Simply add webroot/library to your include_path (which you can either do in php.ini or in your bootstrap) and the autoloader should be able to find the framework.
If you are keen to have a shared version of Zend you may as well just use pear (http://pear.zfcampus.org/) to install it and then as long as you have your include_path set to look in your pear dir ( /usr/share/php on my machine ) then you are good to go.
I would advise only to do this for dev machines though, as others have said it's a good idea to be able to control the versions of zend for each app when in production.
Related
Probably my English is not the best,i will try to re-explain.
SERVER ROOT
—> global_application_folder
-> global_system_folder
—> app_1
- index.php
- local_config_file.php
- local_database_file.php
-> app_2
- index.php
- local_config_file.php
- local_database_file.php
-> app_3
- index.php
- local_config_file.php
- local_database_file.php
In any folder app_N i have "index.php" that takes care to say where to find the application and system folders.
"local_config_file", it should serve to change some settings in "config/config.php" like: $config['base_url'], $config['sess_cookie_name'], etc, etc.
"local_database_file", it should serve to change some settings in "config/database.php".
Everything works, now i have to find a good way to override the configurations i need to change for each app.
In the previous link: http://caseymclaughlin.com/articles/setup-a-local-configuration-file-in-codeigniter, (which explains what I need ), it describes a way but it does not work, perhaps because dated.
Doing various tests, the only working way i've found is to add, for example, at the end of the "config/config.php"
include_once(FCPATH . 'local_config_file.php');
including the file (in this case "local_config_file.php"), that is not found in the "global_appliacation_folder/config" folder, but within the various folders app_N, that's why FCPATH in the path of inclusion.
So if i will be app_1, the included file ("local_config_file.php"), will be inside the folder app_1
I would advise to make it all separate repositories and use and dependency manager. eg. composer for php.
With that approach get better control of individual applications, with easy way how to distribute changes in the core.
This way you can also leave old apps - to depend on older version of the core fixed at a specific version
You can have
core repo
test app 1 repo
depends on core repo
test app 2 repo
depends on core repo and some other repo
test app 3 repo
depends on core repo legacy version
I'm new to working with PHPStorm and am looking for a helper to make requireing files a bit easier. I'm in a file that's nested fairly deep in folders, and I need to require() a file from just under the Project Root in PHPStorm.
Is there a shorthand in PHPStorm (or plain old PHP) which let's me do something like
require('{ROOT}/lib/somefile.php');
Instead of having to use relative paths?
require('../../../../../../lib/somefile.php');
Apache stores the path to the document root folder in an environmental variable which you can access from PHP like this:
$ROOT = getenv("DOCUMENT_ROOT");
Then you can say:
require("$ROOT/lib/somefile.php");
If you are usign IIS see this article in helicron.net.
If it is not an overkill, I would suggest to use an auto loader.
Here is a standalone one from symfony components: http://symfony.com/doc/current/components/class_loader/introduction.html
I am sure that Zend or other frameworks have the same ability.
It handles the location of files and may even remove your need to require files manually.
Reinventing the wheel is cumbersome for production, IMHO.
I downloaded and extracted Zend Framework and it is inside a folder named ZendFramework-2.0.6.
Documentation says that I need to change php.ini - include_path line.
I hope - this is that line (unchanged): include_path = ".;C:\xampp\php\PEAR"
On this page, accepted answer says that i shouldn't change this path (if I understand well).
Could someone clarify where I should place ZendFramework-2.0.6 folder, which path and how I need to change it ?
I'm using xampp 1.8.1.
It's completely up to you but it is a common practice to place it into the vendor directory.
However, I recommend using composer for installation as it automatically installs dependencies and configures your autoloading. It's surely a good idea to start with the Skeleton Application, the README.md explains the installation process with composer.
You don't need to change the include_path in this case.
I'm trying to install Zend_Tools.
I tried the solutions in other questions but anything worked.
I'm using Windows7 with XAMPP therefore my php lies in C:\xampp\php.
I included php into PATH, added my ZendFramework\library to include_path.
I have some other php installations on my system but I think I included it right. php -i | more gives:
Loaded Configuration File => C:\xampp\php\php.ini
and
Zend Extension => 220090626
Zend Extension Build => API220090626,TS,VC9
Now, when I try to run zf.bat. I get the error:
ZF Error:In order to run the zf command, you need to ensure that Zend Framework
is inside your include_path...
I also added an echo of get_include_path() i the top of zf.php it also gives me the right path:
.;C:\xampp\php\PEAR;C:\Users\Felix_2\Documents\programmierung\ZendFramework\libr
ary;C:\Users\Felix_2\Documents\programmierung\ZendFramework\library
In the ZendFramework\library folders is one folder "Zend" with Zend's packages as subfolders, thats the right folder, isn't it?br/>
Don't know how to get this working.
You need to add that Zend folder to your path. So it should be ......ZendFramework/library/Zend that should fix it.
I'm trying to deploy an PHP application which is written with Zend Framework to a shared cPanel server.
There are not many tutorials available on this area online, however, I followed several of them. It is successful to run the test page which proves the zend framework is installed correctly.
However, since cPanel server has a default root directory called public_html/, it is impossible to simply rename it to the Zend Server's default public/.
As a result, I had two options in mind: (Say the project name is AAA)
1) upload my projects under the /public_html/ directory, then the project will be like /public_html/AAA/public, and etc.
However, this one simply fails to work.
My thought would be something wrong here with the baseUrl setting, however, no matter I comment ( which is to remove the baseUrl) or set to the root page, ( in this case /public_html/AAA) both failed.
2) I tried to follow the way listed in this article: http://blog.motane.lu/2009/11/24/zend-framework-and-web-hosting-services/. Still failed.
Can anyone suggest how to do it?
Really appreciate your help!
Just symlink it:
ln -s public public_html
then this structure will work:
htdocs/
myvhost.com/
public/
application/
library/
public_html # this is actually a symlink pointing to public
Whatever you do, dont just throw everything in the publicly accessible area... its just bad form :-)
I don't think ZF cares what you name your "public" directory. It's just the convention that's typically used.
I can't think of any ZF component or common use case where anything explicitly points at "public/...".
A project structure like this should work:
myproject/
application/
library/
public_html/ # this used to be public until you renamed it.