【问题标题】:how to make smarty display php function return如何使smarty显示php函数返回
【发布时间】:2018-04-13 06:53:09
【问题描述】:

我在 php 文件中有这个函数,它已经包含在每个页面中

function ismobile(){
$detect = new Mobile_Detect;
if($detect->isiOS()){
return'ios';
}elseif($detect->isAndroidOS()){
return'android';
} }

我尝试使用此代码在 smarty tpl 文件中获取移动系统

{$ismobile} 

但如果我使用的是 iphone 或 android,它不会像 ios 那样显示系统

【问题讨论】:

  • 在你的控制器中获取函数的返回值并将其分配给一个模板变量。

标签: php function templates return smarty


【解决方案1】:

用js就可以搞定

$(document).ready(function () {
    if( navigator.userAgent.match(/Android/i)){
        //its android
    }
    if(navigator.userAgent.match(/(iPad|iPhone|iPod)/g)){
        //its iOS
    }
});

【讨论】:

    猜你喜欢
    • 2011-02-17
    • 2023-04-09
    • 2022-12-31
    • 2013-05-13
    • 1970-01-01
    • 2021-04-08
    • 2016-12-15
    • 1970-01-01
    • 2012-08-31
    相关资源
    最近更新 更多