douhutongvm382381 2011-06-02 02:47
浏览 26
已采纳

如何在codeigniter中通过代理自动加载移动模板?

dir:
application
 -controllers 
 -models
 -views
 -mobile_views

How do I auto load templates at mobile_views when I use $this->load->view and view by iphone or other mobile phone?

  • 写回答

3条回答 默认 最新

  • douluokuang7184 2011-06-02 02:55
    关注

    Check this

    You can do it in two way. Way 1: Its very simple. In the above answer (the link I have given) add following line in the end of MyController function

    $this->load->_ci_view_path  . = $this->view_type .'/';
    

    You are done. You can simply load view like normal view load.

    Way 2: To autoload a view based on user agent, I think you can implement it using hooks. To implement this hooks you need to follow the following steps

    1. Autoload user agent library in autoload.php

      $autoload['libraries'] = array('user_agent');

    2. Enable hooks in config.php

      $config['enable_hooks'] = TRUE;

    3. Not implement hooks on post_controller_constructor. Add following codes to hooks.php

      $hook['post_controller_constructor'][] = array('class' => 'Loadview', 'function' => 'load', 'filename' => 'loadview.php', 'filepath' => 'hooks' );

    4. Now create a page named loadview.php under hooks directory having following code

    class Loadview
    {
    
        public static $MOBILE_PLATFORM = 'mobile';
        public static $DEFAULT_PLATFORM = 'default';
    
        public function load(){
            $this->CI =& get_instance();
            $view_type = $this->CI->agent->is_mobile() ? self::$MOBILE_PLATFORM : self::$DEFAULT_PLATFORM;
            $this->CI->load->_ci_view_path = $this->CI->load->_ci_view_path . $view_type .'/';
        }
    
    }
    
    1. You are done now. You can simply load view like normal view load.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统