我正在尝试将一组php5变量调用到具有函数的另一个页面中,但是当我运行代码时,它会生成页面错误。以下是我的代码:
if(window.cordova) {
var admobid = {};
if (/(android)/i.test(navigator.userAgent)) {
admobid = {
banner: '',
interstitial: ''
};
}
if ((/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent))) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp();
}
function initApp() {
//Error here
AdMob.createBanner({
adId: admobid.banner,
isTesting: false,
overlap: false,
offsetTopBar: false,
position: AdMob.AD_POSITION.BOTTOM_CENTER //,
//bgColor: 'yellow'
});
//And here
AdMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: true //kalo mau bisa false, nanti panggil manual
});
}
}
请有人告诉我这件事吗?
答案 0 :(得分:0)
目前,您调用函数SocialLinks(),变量被赋值 函数。但是在功能之外无法访问它们。
如果要使用函数外部的变量,则需要返回其内容。例如:
class SocialLinks{
private $bloggerIcon;
private $diggIcon;
private $facebookIcon;
private $stumbleIcon;
public function __construct(){
$this->bloggerIcon = $this->params->get('blogger_icon');
$this->diggIcon = $this->params->get('digg_icon');
$this->facebookIcon = $this->params->get('facebook_icon');
$this->stumbleIcon = $this->params->get('stumble_icon');
}
public function getBloggerIcon(){
return $this->bloggerIcon;
}
public function getDiggIcon(){
return $this->diggIcon;
}
public function getFacebookIcon(){
return $this->facebookIcon;
}
public function getStumbleIcon(){
return $this->stumbleIcon;
}
}
然后在另一页:
$socialLinks = new SocialLinks();
$socialLinks->getBloggerIcon(); //return the blogger icon
答案 1 :(得分:0)
使用JFactory在需要时获取模板参数:
$params = JFactory::getApplication()->getTemplate(true)->params;
您可以访问所需的数据。
$bloggerIcon = $params->get('blogger_icon');