Global Site (Site control) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Global Site (Site control) (/showthread.php?tid=3291) |
Global Site (Site control) - El Forum - 09-22-2007 [eluser]Late Night Again[/eluser] I thought I would share a very simply code I have written to control a whole site from a config file, I call this simple script global site, this allows you to disable a whole site or just one or many controllers so they display a site is currently down message. It also has a feature where you can allow ip addresses to view the site even if it is currently disabled for the rest of the world. I find this script has helped me for any development site I have been creating so only a customer can view the progress and not the rest of the world or if you are doing a major update it is great for testing to make sure a cutover has gone through smoootly while informing others it is currently being updated. The Library Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Global Config Code: $config['disabled_message'] = "The site is currently down for upgrades, please return in the near future."; Inside you constructor Code: class Whatever extends Controller { The View Code: <?php if($this->config->item('disable_site')):?> The view is best set through a container to load content or disabled content files. I find this is best set through the autoload but can also be activated in a controller construct as well. Hope this is helpful to someone else. Global Site (Site control) - El Forum - 09-22-2007 [eluser]llbbl[/eluser] nice idea will come in handy im sure. Global Site (Site control) - El Forum - 09-22-2007 [eluser]Majd Taby[/eluser] that's a good idea, thanks Global Site (Site control) - El Forum - 09-23-2007 [eluser]Kemik[/eluser] This is great, thanks! Just for reference though, how does the script know to pull the global config or are you adding that code to the config.php file? Thanks. Global Site (Site control) - El Forum - 09-23-2007 [eluser]Skulls[/eluser] lol build a library when you can edit the index.php file where the site starts from ... you can put in front ... an array with some ips and then put the condition Code: $allowed_ips=array('ip1', 'ip2'); //etc Global Site (Site control) - El Forum - 09-23-2007 [eluser]Late Night Again[/eluser] [quote author="Kemik" date="1190573622"]This is great, thanks! Just for reference though, how does the script know to pull the global config or are you adding that code to the config.php file? Thanks.[/quote] I just call this in the autoload.php because it needs to be called for each controller that loads Global Site (Site control) - El Forum - 09-23-2007 [eluser]Late Night Again[/eluser] [quote author="Skulls" date="1190580430"]lol build a library when you can edit the index.php file where the site starts from ... you can put in front ... an array with some ips and then put the condition Code: $allowed_ips=array('ip1', 'ip2'); //etc Yes that may be true and comment accepted, but this also checks if each controller is active and I may not want to disable the whole site, it aslo loads it directly into the current template structure of the page and did not want to call a die with just an error message by itself. I am sure there is probably a better way of doing this but I wanted to have a lot more control over each seperated controller than the whole site |