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.

3
  • 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? Commented Jan 13, 2014 at 8: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. Commented Jan 13, 2014 at 8:34
  • check the answer below. Commented Jan 13, 2014 at 8:45

2 Answers 2

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');
        }
  }
}
Sign up to request clarification or add additional context in comments.

18 Comments

link please check the user.php controller because here i fix same as above thanks for the both versions
your link is having old code only.you did not add the above code.
its old code of user.php controller for thanks i ask can i add the same code as you mention above?
in the user.php how i add for the mobile version because this code only for the default view
i ask i make a new function for mobile or in the same function i try the code?
|
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
}

6 Comments

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?
You don't need me to write your code for you, surely? You'll need curly braces around your if/else statements.
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
Put curly braces around your statements and only call a single view. if ($statement) { //do something }
' 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?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.