0

I made a website but in two versions one for normal users and one for the mobile users and for both I made view page and also with multilanguage options, first I add in controller

public function index()
    {
        if ($this->input->get("lang") =="en")
            $this->load->view('en_signup');
        else
            $this->load->view('ar_signup');
        $this->load->helper('url');
    }
}

I made pages with name of marabic.php and menglish.php for mobile users now first I need to load these pages also but not mix with the original/default view pages, because I already mention java cript in default view page when its detect mobile user it redirect to m.domainname.com now I want to figure out this issue, please suggest.

Christian Giupponi
  • 6,801
  • 8
  • 55
  • 99
FormaL
  • 359
  • 2
  • 4
  • 19
  • this means if your language is english you need to load `en_signup.php` for website and `menglish.php` if mobile user, same for arabic.right? – user2936213 Jan 13 '14 at 08:27
  • yes you are right, right now what the controller do default open form in arabic okey on arabic form i mention english anchor so if any one need english click and go on english, now i made a mobile version for the same website so i need to control two views , even i use java script for mobile detection in default view when url is open it check if user from mobile redirect it. when i use to load the view so it mix both mobile and normal view. – FormaL Jan 13 '14 at 08:34
  • check the answer below. – user2936213 Jan 13 '14 at 08:45

2 Answers2

1

You can detect if a user is visiting from a mobile device by using CodeIgniter's User Agent library.

$this->load->library('user_agent');

if ($this->agent->is_mobile()) {
 // Load mobile view
}
mcryan
  • 1,496
  • 10
  • 19
  • `public function index() { if ($this->input->get("lang") =="en") $this->load->view('en_signup'); else $this->load->view('ar_signup'); $this->load->library('user_agent'); if ($this->agent->is_mobile()) { if ($this->input->get("language") =="english") $this->load->view('menglish'); else $this->load->view('marabic'); } $this->load->helper('url'); } }` its correct? – FormaL Jan 13 '14 at 08:06
  • You don't need me to write your code for you, surely? You'll need curly braces around your if/else statements. – mcryan Jan 13 '14 at 08:11
  • when i load the view only for mobile it mix index view page and mobile view two views mix it how can i sort out – FormaL Jan 13 '14 at 08:21
  • Put curly braces around your statements and only call a single view. `if ($statement) { //do something }` – mcryan Jan 13 '14 at 08:22
  • ' public function index() { if ($this->input->get("lang") =="en") $this->load->view('en_signup'); else $this->load->view('ar_signup'); } public function mobile() if ($this->agent->is_mobile()) { $this->load->view('marabic'); else $this->load->view('ar_signup'); } $this->load->helper('url'); $this->load->library('user_agent');' now its correct? – FormaL Jan 13 '14 at 08:31
  • No. You need to go to be very basics of programming. Pasting that into my editor shows several syntax errors. – mcryan Jan 13 '14 at 08:41
1

Try this:

public function index()
{
    $this->load->library('user_agent');
    $this->load->helper('url');
    if ($this->input->get("lang") =="en"){
        if ($this->agent->is_mobile()) {
          $this->load->view('menglish');
        } else {
          $this->load->view('en_signup');
        }
    } else {
        if ($this->agent->is_mobile()) {
          $this->load->view('marabic');
        } else {
          $this->load->view('ar_signup');
        }
  }
}
user2936213
  • 1,041
  • 1
  • 8
  • 19
  • [link](http://pastebin.com/6h6BUxT0) please check the user.php controller because here i fix same as above thanks for the both versions – FormaL Jan 13 '14 at 08:51
  • your link is having old code only.you did not add the above code. – user2936213 Jan 13 '14 at 08:52
  • its old code of user.php controller for thanks i ask can i add the same code as you mention above? – FormaL Jan 13 '14 at 08:55
  • in the user.php how i add for the mobile version because this code only for the default view – FormaL Jan 13 '14 at 09:00
  • i ask i make a new function for mobile or in the same function i try the code? – FormaL Jan 13 '14 at 09:07
  • right now dont have online hosting that's why i made and ask check the syntax and loop its fine. – FormaL Jan 13 '14 at 09:21
  • Yeah it seems fine :) – user2936213 Jan 13 '14 at 09:25
  • oh yay! thanks to you for pushing me to make a logic :D – FormaL Jan 13 '14 at 09:31
  • one more thing i wana ask, after the submission of form in database i wana generate confirmation from our side – FormaL Jan 13 '14 at 10:50
  • so for that you can use `$this->session->set_flashdata();`. For more details see this: http://ellislab.com/codeigniter/user-guide/libraries/sessions.html – user2936213 Jan 13 '14 at 11:02
  • [link](http://pastebin.com/GBMUSvPp) Please check The code as i discuss with you, now the default page when i submit the form it shows no page found even data not submitting in db please suggest old working default page also off. – FormaL Jan 13 '14 at 12:08
  • Where did you load `$this->load->library('user_agent');` library? – user2936213 Jan 13 '14 at 12:09
  • In Controller Two Files I have welcome.php & user.php both file codes i share. – FormaL Jan 13 '14 at 12:14
  • you need to load this library in users.php controller also if you are using `$this->agent->is_mobile()` in users.php controller – user2936213 Jan 13 '14 at 12:23
  • `class User extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('form'); $this->load->helper('url'); $this->load->library('user_agent');` I load library but when i submit form shows page not found. – FormaL Jan 13 '14 at 12:28
  • this code not work , quit this tommorrow i will made again from scratch and see if i am stuck any where i will buzz you, thankyou so much – FormaL Jan 13 '14 at 14:42
  • [link](http://stackoverflow.com/questions/21109216/parse-error-in-controller-file) Please suggest – FormaL Jan 14 '14 at 09:32
  • [link](http://stackoverflow.com/questions/21201276/codeigniter-email-class-registration-after-submission) please suggest. – FormaL Jan 18 '14 at 14:44