Setup a local configuration file in Codeigniter - php

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

Related

Yii2 configuring to use vendor folder in an external http storage

I have multiple restful apis build using yii2 framework, What i wouldlike is to use a single vendor directory stored in a different address
That is
I have an application hosted at www.example1.com and another one hosted at www.example2.com and the one i would like to contain the vendor files to be at www.example3.com so that in both example1 and example2 i only have to upload the resful folder without vendor directories
After some looking into yii2 advanced folder i have found these lines in index.php
require(__DIR__ . '/_protected/vendor/autoload.php');
require(__DIR__ . '/_protected/vendor/yiisoft/yii2/Yii.php');
Ive tried as a work around by doing
require(__DIR__ . 'http:://example1.com/pathto/_protected/vendor/autoload.php');
But the above fails, How best can i achieve this
You can't do it via HTTP.
The only solution is to create shared, NFS volume, which will be mounted on both servers as your vendor/ directory. After you will be able to use the same vendor dir for two servers.
If those two sites are deployed to the same server, it might be easier.
It is very simple .
you can just copy the vendor file into your next project and change the two lines of required file path (autoload.php & yii.php) to the correct vendor location.
the /config/web.php. add vendorPath to the config with your vendor directory.
As the vendor is moved from /var/www/html/myapp/vendor to /var/www/html/frameworks/yii2, you will find problem installing a new extension or updating the existing through composer command. To fix it, modify your composer.json (right under your project directory) by adding the vendor-dir attribute under the config section, eg:
// other settings ...
"config": {
"vendor-dir":"your path",
"process-timeout": 1800
},
// other settings ...
Also, you may find "a man-in-the-middle attack" message when either update or install the new extension (i don't know if there is a relation to the modification of composer.json but i get it several times during experiments). To fix it run composer update --dry-run. then it would ok.
This can be done: Include through http.
You need to set some php variables (allow_url_include, allow_url_fopen). And you need to get rid of __DIR__ constant in front of your php file path:
require('http://example1.com/pathto/_protected/vendor/autoload.php');
BUT
Don't do this. Really. You don't want to go through all these unsafe php setups. And you don't want to expose your vendor files to all the people in the world. If your script can access php source code via http, everyone can. Also, includes over http will be extremely slow.
The (probably) only solution
If you really want to share core php files between multiple websites, you can purchase virtual server, set up both websites on it and create one folder accessible from all websites on this server.
You don't even need virtual server, you can go with some kind of multihost service with custom folder for each website and shared folder for core (vendor) files.

Setting up preview of Yii2

The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:
php yiic.php app/create /var/www/yii2
With the error:
Could not open input file: yiic.php
Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:
The following commands are available:
- asset
- cache
- help
- message
- migrate
Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?
Seems like yiic has been removed for now, there are alternatives though, so read on.
It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.
There are 2 ways to do this now:
Use composer. (I recommend this option.)
Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.
There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.
For basic go through the basic readme.md, and for advanced go through the advanced readme.md.
The directions for using composer are given in the respective readme.md files. Including them here for completeness:
Basic app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
Access app from http://localhost/my_yii2_trial/www
Advanced app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command). Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Here's how to copy the directory and get it working:
Basic app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php.
For me it was within yii2/framework/yii/
comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
Access from browser : http://localhost/my_yii2_trial/www
Advanced app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.
I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.

which folders to ignore in a codeigniter app when using version control

Which folders should I ignore when using version control on a project developed on the CodeIgniter framework?
I am already ignoring the application/cache folder, but are there any else?
You can ignore any application generated logs and any development specific configuration files. Here's a commonly used .gitignore file for CodeIgniter:
*/config/development
*/logs/log-*.php
*/logs/!index.html
*/cache/*
*/cache/!index.html
https://github.com/github/gitignore/blob/master/CodeIgniter.gitignore
Beyond the default github codeigniter template provided by birderic, (at https://github.com/github/gitignore/blob/master/CodeIgniter.gitignore for good measure) I also like to simply exclude any php file in the /config director with
*/config/*.php
Some third party apps, like HybridIgnite, like to put their configuration files in the /config directory and a limited config block might enable on of these files to be tracked... Better safe than sorry...
To make it clear how config files should work, I keep a copy of the default files (with no passwords of course) in a seperate config_template directory.
HTH,
-FT

Autoloading classes when not in same directory as zend library

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.

Can I customize the Magento app/code/core folder without affecting future upgrades?

I found a guide on how to add new attributes to users, it explains that for this operation I must modify some files in the app / code / core / Mage directory (the directory that contains Magento’s modules).
But if i make some changes in that folder will this affect future upgrades?
Will an upgrade will delete my changes?
Should I limit the changes only to my modules to not have problems with updates?
You can also make a copy of the file in app/code/local/ with the same directory structure as the file has under app/code/core/. File under local will override those under core and will not be affected by upgrades.
For example:
app/code/local/Mage/Checkout/Block/Onepage/Billing.php
will override:
app/code/core/Mage/Checkout/Block/Onepage/Billing.php
and will not be overwritten by upgrades. Note that this will only work for Block and Model files.
You can also override files through custom modules with the config.xml file, although this is a bit more advanced.
Yes, changes such as these will be overwritten.
If you have such changes, try to:
keep core changes to a minimum
document any changes you make
report the issues on the Magrnto web site so that the changes can be replicated for everyone else
Controllers would work as well if you enable that Module in local space
local vs core controller

Categories