Multiple Dynamic Domains Using ONE Codeigniter Installation - codeigniter

One of my jobs is to manage 58 sites for properties spread out across the country. They each have their own domain and are all housed in the same Dedicated Virtual Serve at Media Temple. The sites which are about 19 pages each use the exact same html/css/php code. The images are served to each site from a central repository living in different folders for each theme used.
What I want to do is to install one single installation of CI2 including the application folder because everything that is different between the sites is stored in the database. As long as I can give the controller a unique property number (which I would hope I could do when they access the index.php page in each domain), then all of my sites will work fine.
In all the answers I have read, the suggestion is to replicate the application folders and just reuse the core. What would work best for me is to also reuse the application folder. Then when I make a modification, it will cascade to all sites without me having to touch 58 pages.
Is this possible?

If all files are the same and the only thing changing between apps is the data from the database, then you can do this:
Point all domains to your docroot for the CI install
in your index.php, determine which db connection you need to use for the currently requested domain:
// index.php
$domain = $_SERVER['SERVER_NAME'];
switch ($domain)
{
case 'www.firstsite.com':
$this->load->database('firstsitedb');
break;
case 'www.secondsite.com':
$this->load->database('secondsitedb');
break;
default:
show_error('No Site Found');
break;
}
** OR **
If they each use the same database, and you need to be able to use a variable in your queries, then just set a constant based on the switch/case instead of loading a different database. Then you can use that constant throughout your application in your queries.
// index.php
$domain = $_SERVER['SERVER_NAME'];
$site_id = 0; // default
switch ($domain)
{
case 'www.firstsite.com':
$site_id = 1;
break;
case 'www.secondsite.com':
$site_id = 2;
break;
default:
show_error('No Site Found');
break;
}
define('SITE_ID', $site_id);

With Codeigniter 2.2, the index.php now allows the setting of a config array item (the feature is documented in that file). So it is possible to save the requested domain as a site variable in effect by doing this:
$assign_to_config['site_domain'] = empty($_SERVER['SERVER_NAME']) ? 'default.dev' : $_SERVER['SERVER_NAME'];
Later you could match this site_domain string against a database look-up to fetch the requisite content & theme views etc.

Related

Magento two shared websites, but want to make frontend changes in one of them

We've been using two shared websites for some time. I've used the subdirectory method as indicated here (https://www.crucialhosting.com/knowledgebase/setup-multiple-magento-stores). So both websites have a shared admin panel and share the file system.
But we want the possibility to make some changes for the second site compared to the first. The second website is for our physical store so we could decide to not allowe customers to place an order, but only show which products we have in the physical store and the actual stock levels.
I would do that by making changes in app/code or app/design, etc. But because both sites share the same files, I can't regularly change a file without making a change to both websites.
So the question is:
Do I need to setup the two sites in a different way, or is there a way to make changes in some files to differentiate results depending on the site the customer is seeing? If site = 2 then do not show the shopping cart, etc.
We're using Magento 1.7.
There are multiple ways of providing dynamic content/features in Magento based on website.
Below are two easy ways to implement conditional content by store.
The first is to leverage the theme folders per site.
Navigate to app/design/frontend/theme/yourpackage/yourtheme/
Duplicate this folder twice:
app/design/frontend/theme/yourpackage/store1/
app/design/frontend/theme/yourpackage/store2/
Navigate to admin panel: admin/system_config/edit/section/design/
Change Current Configuration Scope to store1 and set all of theme options to point to your newly created theme store1/store2.
Now both websites will use their own template & layout files which you can customize without them interfering with each other.
The second option is simpler but long term may not be the best
solution.
Go to where you want to add a store conditional and drop in this if statement:
if( strtolower( Mage::app()->getStore()->getCode() ) === 'store1' )
{
}
else if( strtolower( Mage::app()->getStore()->getCode() ) === 'store2' )
{
}

CodeIgniter to run from a subdirectory of another codeigniter installation

I am trying to find a way to run codeigniter from a sub-directory of another codeigniter installation. The CI from the sub-directory would be for testing and the main one is the live site. Anyone could advice on this or any other better approach ?
I believe you can just place this in the root folder and set the base url in the config :
$config['base_url'] = 'http://www.example.com/testsite/';
then it works.
There can be issues with the first application serving the 404 pages when a route is not matched however
I am posting the answer here, because is too long to use it as a comment...
I made it thru another approach: setting different $active_group in the config/database.php file.
So, first I have checked for a parameter in $_GET, if that is set we use a group, otherwise the default group (the other group is used for testing - a separate database, exact structure but without touching the main db)
if(!isset($_SESSION)){session_start();}
if (isset($_GET["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
$_SESSION['debugmode'] = true;
}elseif (isset($_SESSION["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
}elseif(!isset($_GET["debugmode"]) && !isset($_SESSION["debugmode"])){
$active_group = 'default';
$active_record = TRUE;
}
To make sure this will work on all the controllers /views, because we wont have that $_GET parameter all over the application, we can set that session value once we have that $_GET parameter present. Also, we have to make sure we destroy that session when we log out or after an amount of time.
Reason of using a Session value: by default CI is using that table to store the sessions, without using our session value, it will force somehow to use the default DB, or at least I couldn't find it to trick this step.

Extending Joomla 2.5 Banner Component

I really hope someone can help me.
I need to be able to serve banners in categories which are dependant on a session variable - and can't find a component which does that. So I'd like to extend the Joomla Banner component in order to select banners based on a session variable which contains the category path.
The correct session variable is being stored correctly.
In order to do this I added an option in the banners module .xml to allow for a session variable and the name of the session variable. This is being stored correctly in the module table within the params field along with the other module parameters.
Then I started on the
components > banners > com_banners > models > banners.php
by adding two lines of code in getListQuery where the SQL is assembled. They are:
$sess_vars = $this->getState('filter.sess_vars');
$sess_vars_name = $this->getState('filter.sess_vars_name');
But both variables contain nothing even though the ones the component already has can be retrieved fine. Without a doubt I need to change something somewhere else as well - but just can't figure out what to do.
Any help would be greatly appreciated.
The first thing to do is not hack the core files, hacking the core prevents you from using the built-in update feature to apply the regular bug fixes and security patches released by Joomla! (e.g. the recently released 2.5.9 version).
Rather make a copy of them and modify it so it's called something else like com_mybanners. Apart from the folder name and the entry point file (i.e. banners.php becomes mybanners.php) you will also want to update the components banners.xml to mybanners.php.(You will need to duplicate and modify both the front end /components/com_banners/ and /administrator/components/mybanners.php.)
Because of the way Banners work (i.e. banners are displayed in a module) you will also need to duplicate and modify /modules/mod_banners/,/modules/mod_banners/mod_banners.php and /modules/mod_banners/mod_banners.xml. Changing mod_banners to mod_mybanners in each location.
In Joomla! components the state is usually populated when JModel is instantiated, however, in this case the component is really about managing banners and recording clicks the display is handled by mod_banners. So, you will want to add some code to mod_mybanners.php to use the session variables you want to act on. Normally when a models state is queried you will collect the variables via JInput and add them to your object's state e.g.
protected function populateState()
{
$jApp = JFactory::getApplication('site');
// Load state from the request.
$pk = $jApp->input->get('id',0,'INT');
$this->setState('myItem.id', $pk);
$offset = $jApp->input->get('limitstart',0,'INT');
$this->setState('list.offset', $offset);
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
// Get the user permissions
$user = JFactory::getUser();
if ((!$user->authorise('core.edit.state', 'com_mycomponent')) && (!$user->authorise('core.edit', 'com_mycomponent')))
{
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
}
The populateState() method is called when a state is read by the getState method.
This means you will have to change your copy of /components/com_banners/models/banner.php to capture your variables into the objects state similar to my example above.
From there it's all your own code.
You can find all of this information in the Developing a Model-View-Controller tutorial on the Joomla Doc's site

Adobe AIR HTML - How do I dynamically load an image located in app-storage?

I'm working on an AIR application which generates a dynamic client presentation, pulling all necessary data from a PHP framework API. In the process, I download a large number of images and store them locally in the user's app-storage (air.File.applicationStorageDirectory).
Side note: the HTML view I am dynamically populating is located in an IFRAME sandbox.
I have a parsing script which attempts to take JSON data and populate the page with the necessary fields. Many of these fields are images that I need to locally reference. I thought I might be able to simply generate the URL using <img src="app-storage:/path/to/img.jpg"> but it doesn't seem to actually load the image. My guess is AIR doesn't handle app-storage: url references dynamically. Is there a work-around for this? Could I perhaps use jQuery and load()?
Here is the current code I am using which is not working:
var pos = filename.lastIndexOf(".");
if (pos != -1) {
ext = filename.substr(pos + 1, filename.length);
switch (ext) {
case 'gif':
case 'jpg':
case 'jpeg':
case 'png':
default:
// update the source value
$field.attr('src', 'app-storage:' + filename);
break;
}
}
I thought I might be on the right track because the return result of
air.File.applicationStorageDirectory('test')
was app-storage:/test
Any help would be greatly appreciated!
The solution ended up being that I had to properly set the IFRAME to have Application security level access, granting it privileges to use handle app-storage urls properly. For those interested in knowing how you can go about doing this, the first step is to simply have the IFRAME file you wish to load directly in the application's main directory:
<iframe id="childFrame" src="child.html" documentRoot="app:/" allowcrossDomainxhr="true" width="100%" height="100%"></iframe>
The key difference in this sandbox is that it doesn't have the parameter sandboxRoot.
It's worth noting that I never once experienced any security errors during any of my testing. It seemed as though the app-storage URL was just not properly being handled by AIR itself.
people talking than you need to allow security policy there.

How to not cache a php file where a cachemanifest is beeing called?

i'm building a iphone app with jqtouch and i use a cachemanifest to cache all the static files (images, css, javascript) to make it load faster. However the page uses php for the dynamic content and i don't want to cache that. So i'm generating the cachemanifest with this php-script(manifest.php):
<?php
header('Content-Type: text/cache-manifest');
echo "CACHE MANIFEST\n";
$hashes = "";
$lastFileWasDynamic = FALSE;
$dir = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($dir) as $file) {
if ($file->IsFile() && $file != "./manifest.php" &&
substr($file->getFilename(), 0, 1) != ".") {
if(preg_match('/.php$/', $file)) {
if(!$lastFileWasDynamic) {
echo "\n\nNETWORK:\n";
}
$lastFileWasDynamic = TRUE;
} else {
if($lastFileWasDynamic) {
echo "\n\nCACHE:\n";
$lastFileWasDynamic = FALSE;
}
}
echo $file . "\n";
$hashes .= md5_file($file);
}
}
echo "\nNETWORK:\nhttp://chart.apis.google.com/\n\n# Hash: " . md5($hashes) . "\n";
?>
This actually works really good except for one irritating thing:
From what i read somewhere the file that calls the cachemanifest is automaticly included in the manifest and is beeing cached. Wich means that my start-page index.php, where i call the cachemanifest is beeing cached. This leads to very irritating problems.
is there any way to deal with this or any smart workaround? The page is in the cachemanifest listed as NETWORK, but it looks like this is beeing overruled by the fact that the cachemanifest is called from the file.
futta's idea is right, but what you will probably find is that only one section of your frontpage changes often. Leave that empty, then let the rest of the page be cached and don't worry about it. When you visit the page, the cached version is called up instantly, and you can run a script to grab the dynamic page fragment from the server and set it with innerHTML to complete the page. The effect is that there is still one HTTP request (plus one for the manifest), so it is no slower, and it addition you can show part of your app while the dynamic section is being downloaded. If you ever want to refresh the whole page, have a comment in the manifest marking the version, and increment that to reload the whole app.
Clean and neat. I think that is how the system is intended to be used, without trying to avoid a bit of javascript, since that is after all the only way you can play around with the offline and do useful things with the app when offline.
I have the same experience, but have the following possible workaround on my todo-list:
create a manifest with all static assets
include a reference to that manifest in only one html-page (buildCache.php)
check if window.applicationCache is supported and if so:
redirect once per session to cache.html to create/check/update the cache
have buildCache.php display some info about what is being done (using the applicationCache eventlisteners)
have buildCache.php redirect back to normal index (where the manifest is not defined)
I hope (and someone claimed this is the case in a comment on my blog) that all pages on the same domain will use the static assets in the applicationCache, even if the manifest is not referenced in all of them.
Another solution would be to keep your index.php as a blank loading page or splash screen of some sort, then redirecting the user to the actual dynamic php page. Since the manifest is in index.php and index.php redirects to real-index.php the problem might be less anoying.

Resources