1

Web サイト用に持っているものと同じモデルとコントローラーを使用し、アプリケーション ディレクトリに 2 つの個別の「Views」フォルダーを作成します。1 つは Web バージョン用、もう 1 つはモバイル バージョン用です。それ以外の場合は、デスクトップ ビューとモバイル ビューからアクセスされます。

編集: これは、Codeigniter/system/loader.php でビュー フォルダー パスを割り当てる関数です。

function __construct() { 
$this->_ci_view_path = APPPATH.'views/'; 
$this->_ci_ob_level = ob_get_level(); 
$this->_ci_library_paths = array(APPPATH, BASEPATH); 
$this->_ci_helper_paths = array(APPPATH, BASEPATH); 
$this->_ci_model_paths =     array(APPPATH); 
log_message('debug', "Loader Class Initialized"); 
}

したがって、ここでこのチェックを適用すると:

if($this->agent->mobile()){ 
$this->_ci_view_path = APPPATH.'views/mobile_view';
}

これは行く方法ですか?–

4

2 に答える 2

1

このリンクは、Web アプリケーションがアクセスされているデバイスの種類を特定するのに役立つ場合があります。同じライブラリを作成し、コントローラーのクラスのコンストラクターに含めます。

これで、次の方法でビューを変更できます。

if ($detect->isMobile()) {
         $view_folder = 'views/mobile/';
}
else{
         $view_folder = 'views/normal/';
}
$this->load->view($view_folder.index, $data); //$data is the same variable that you are going to use into your views.
于 2013-09-30T07:18:08.850 に答える
0

または、Codigniter http://ellislab.com/codeigniter/user-guide/libraries/user_agent.htmlが提供する userAgent を使用できます。

EDITED Loader.php 以下のようなカスタムビュー関数を作成します

public function my_view($view, $vars = array(), $return = FALSE)
{
    $CI =& get_instance();
    $CI->load->library('user_agent');
    if ($CI->agent->is_mobile())
    {
        // mobile view code goes here
        //return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
    }
    else
    {
        // browser code goes here
        //return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
    }
}
于 2013-09-30T07:47:51.867 に答える