|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Sat Dec 05, 2009 12:56 am Post subject: Same DOCUMENT_ROOT location, different subdomain names |
|
|
This is a bit advanced knowledge on powerfully extending Smarty for different server. Let us take a case of two closely related domain names or subdomain names. Now, I want to put the PHP Scripts of these sites into a common location, but I want to run them as different services using different subdomain names.
In my example, let us suppose that positive.sanjaal.com and jobs.sanjaal.com are two closely related products. The first basic thing I am doing is to point these different names to common public_html directory. (This is NOT possible in some servers, while in dedicated or in advanced control panels, you can define your pointers yourself.)
Now, let me show, how positive.sanjaal.com and jobs.sanjaal.com work differently even though their DOCUMENT_ROOT is the same public_html.
And here are my directory structures
library/classes/smarty/
library/temp/smarty_compiles/
library/temp/smarty_cache/
library/services/jobs.sanjaal.com/controllers/
library/services/jobs.sanjaal.com/templates/
library/services/positive.sanjaal.com/controllers/
library/services/positive.sanjaal.com/templates/
Now let us see the dynamic configurations for Smarty:
Code: |
# dynamically read templates for different server names
$smarty->template_dir = __ROOT__."/library/services/{$_SERVER['SERVER_NAME']}/templates";
# Make this an array, so that it is able read out plugins from different locations
$smarty->plugins_dir[] = __ROOT__."/library/services/{$_SERVER['SERVER_NAME']}/plugins";
# Make sure that the compliled files will not be overwritten, using this unique ID.
$smarty->compile_id = preg_replace('/[^a-z]/is', '', $_SERVER['SERVER_NAME']);
# Use common location for compiles and cache.
$smarty->compile_dir = __TEMP__.'/smarty_compiles';
$smarty->cache_dir = __TEMP__.'/smarty_cache';
|
Also note that I have used compile_id, that we would NOT do normally. If in case two subdomains have same file names, this prevents overwriting the Smarty's compiled files.
Here, the controllers (core php files and other configurations) in each site and the templates for each site are read dynamically from their specific locations. As the templates have different layouts and contents, the two sites: jobs.sanjaal.com and positive.sanjaal.com contain entirely different look and contents.
However, we can still reuse few things like images and javascripts using any of the subdomain names. Plus, you have a chance to minimize the site’s overall coding because of heavy reuse among the sites (like database, class files, APIs, and smarty plugins). And, if you different domain names (not just subdomains) are related, then you can choose this option.
How did you like this configuration? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|