codeigniter - controller load multiple views

核能气质少年 提交于 2019-12-25 02:22:43

问题


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.


回答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');
        }
  }
}



回答2:


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
}


来源:https://stackoverflow.com/questions/21086233/codeigniter-controller-load-multiple-views

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!