down_load1117 2014-09-23 13:05
浏览 87
已采纳

CI路由$ this-> agent-> is_mobile()

Is there any way in the CI routing file I can find out if a view is using a mobile?

and if so rotate them to a different page?

I've got two sets of controllers one for mobile and one for desktop but I'd like the urls to always be the same.

I've tried adding the following code to the routes config file but I'm getting an error...

Am I thinking about this totally wrong?

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

if ($this->agent->is_browser())
{
      $route['default_controller'] = "index";
} elseif ($this->agent->is_mobile())
{
      $route['default_controller'] = "m/index";
}

The error I'm getting is Undefined property: CI_Router::$load

  • 写回答

1条回答 默认 最新

  • dpvp56187 2014-09-23 15:15
    关注

    From examining the CI system files, it appears that the Loader class is loaded after the Router class, so $this->load doesn't exist yet.

    Check out CI Hooks, though: https://ellislab.com/codeigniter/user-guide/general/hooks.html

    In addition, you might try using head.js (http://headjs.com/) and defining screen widths for Responsive Design. It enables you to build a web site and change the CSS to change the page depending on the width of the browser. Unless you are aiming at mobile/desktop due to functionality, screen size is the common reason we care what they are on, right? So, if it is screen size, I think the head.js system is the way to go. Then you have only one codebase of server-side stuff to worry about.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题