Skip to main content

How To Load Different View For Mobile Devices In CodeIgniter 3 - PHP




How To Load Different View For Mobile Devices In 
CodeIgniter 3 - PHP



User Agent Class


The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site. In addition, you can get referrer information as well as language and supported character-set information.


The User Agent class is initialized in your controller using the $this->load->library function:


$this->load->library('user_agent');
The name of the web browser viewing your site:


$browser = $this->agent->browser();

> Home Controller



<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
    public function index()
    {
// Load User Agent Library [OR autoload.php file]
$this->load->library('user_agent');
if ($this->agent->is_mobile()) {
// Pass Data in View File
$data_array['title'] = "Mobile Page Title";
// Mobile View Template
$this->load->view('home/_mobile/index', $data_array);
} else {
// Pass Data in View File
$data_array['title'] = "Page Title";
// Other Plateform View Template
$this->load->view('home/index', $data_array);
}
    }
}

> Main View File


<h1>Main View Template</h1>
<small><?= $title ?></small>
<br>
<?php
$is_mobile = $this->agent->is_mobile();
var_dump($is_mobile);
?>
> Mobile View File

<h1>Mobile View Template</h1>
<small><?= $title ?></small>
<br>
<?php
$is_mobile = $this->agent->is_mobile();
var_dump($is_mobile);
?>

Comments

Popular posts from this blog

Support Page - Fill Excel Data - CTH (Google Chrome Extension)

Fill Excel Data - CTH (Google Chrome Extension) Download Link Video GitHub Support Links:

#3 CodeIgniter 4 Beginner Tutorial - Module Base CodeIgniter 4 Project (HMVC) [SUBTITLES]

#3 CodeIgniter 4 Beginner Tutorial - Module Base CodeIgniter 4 Project (HMVC) [SUBTITLES]

Youtube Random Comment Picker V3 - Open Source Project

Youtube Random Comment Picker V3 Use it to choose from giveaway winner YouTube video comments. YouTube Comment Picker V3.0.0 πŸ‘‰ Selecting a random comment from one of the YouTube video comments. πŸ‘‰ Picking a random winner from video comments. πŸ‘‰ Generating SVG and QR codes to the winner's data. πŸ‘‰ Sharing the winner's data on Social Media Account. πŸ‘‰ Comment Picker you can Play and Pause according to your need. πŸ‘‰ YouTube Video and winner's data are saved in the Browser Local Storage (IndexedDB). πŸ‘‰ Our Project's API runs Multi Request at a time that gives us Super Speed. πŸ’» Open Site: https://yt-rcp.netlify.app/ http://yt.ctechhindi.in/ πŸ““ Source Code: https://github.com/ctechhindi/YouTube-Comment-Picker Video Tutorial:  πŸ“ Other Projects : πŸ‘‰ https://youtube-cm2.netlify.app/#/ πŸ‘‰ https://youtubeblade.netlify.app/#/ πŸ‘‰ https://speedtyping.in/ πŸ”΄ Subscribe to My Youtube Channel: https://goo.gl/rN2644 πŸ’° Support by Donating - PayTm:...