Quantcast
Channel: Aafrin.com » Web
Viewing all articles
Browse latest Browse all 12

Making Your Web Application Offline In CodeIgniter

$
0
0

Some of the web application developed requires to be put in offline state, when the web application goes upgrades or maintenance. It is best to code a function that can set the web application system either online or offline rather than doing it manually. Here is a small method that can be used to make the web application offline in CodeIgniter. The mySQL database schema, Model and the Controller is included below.

MySQL
The following method will be using the database schema as shown below. The settings table would have a column for the system status (stgs_status) with the value of either ‘Online or ‘Offline’. The first record is inserted with the id value of 1 and the status as online.

CREATE TABLE `settings` (
  `stgs_id` int(11) NOT NULL AUTO_INCREMENT,
  `stgs_status` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`stg_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1$$

INSERT INTO `tracking`.`settings` (`stg_id`, `stg_status`) VALUES ( 1, 'Online' );

Model
The model below queries the settings table and checks the value of the system status(stgs_status) from the settings table and returns the value. The system status column is checked whether the system is online or offline and the view is loaded according to the status in the system status column.
The function below specifically checks for the value of system status from the row with the id ’1′ as the
status for the system is stored in the record with id 1 as shown in the database schema above.

/*
* 	Function Name 	:
* 	Description		: get record details from database
*/
function check_app_status()
{
$this->db->select('stgs_status');
$this->db->where('stgs_id', 1);
$query = $this->db->get('settings');
return $query;
}

Controller
In the controller below, the index function loads the settings model and then call the check_app_status to check the system status from the settings table. Once the column has been retrieved, the index function than check the value stored in the system status column. The index function loads the view according to the system status set, if the system status is set to online than it loads the log in page and if the system status is set to offline than it load the offline view.

public function index()
{

$this->load->model('settings_model');
$row = $this->settings_model->check_app_status()->row();

	if ($row->stgs_status=='Online')
	{
		$this->load->view('login');
	}

	if ($row->stgs_status=='Offline')
	{
		$this->load->view('offline');
	}
}

P/S : The following function can be included in your back-end control panel where the value for the settings columns in the settings table can be updated within the web application itself.


Viewing all articles
Browse latest Browse all 12

Trending Articles