• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Snippet] Setting Homepage offline/under construction /...

#1
Hello,

I have no idea if this is useful for somebody, but I thought I share it.

In some cases it is necessary to set the whole page for visitors "offline" or "maintenance" or "under construction" and/or whatever.

It is a simple snippet not only based on codeigniter of course.

Create a database "global_settings" with rows

id (PK)
status

Make status an "enum" field with following values.

online
offline
construction
maintenance
what_ever_you_need


Prepare a view (status.php) in "views/error" something like

Code:
<html>
<head>
<title><?=$error_title;?></title>
</head>
<body>
<?=$error_message;?>
</body>
</html>


Go to "Base_Controller" and put this in the constructor/init:


PHP Code:
$result $this->db->query('SELECT status FROM global_settings WHERE id = 1')->getResultArray();
            
if( in_array($result[0]['status'], array( 'offline''wartung''konstruktion' ) ) )
{
     
$error = array( 'offline' => 'Sorry, we are offline.',
                     
'maintenance' => 'Come back later.',
                     
'construction' => 'Hey, a new Webpage is coming soon.' );

     dieview('errors/status', ['error_title' => $result[0]['status'], 'error_message' => $error[$result[0]['status']] ] ) ); 


This is the basic usage.

Of course one can check, if a certain User is logged in (e. g. Admin) to avoid showing the offline/maintanence/construction message.

Greetings.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.