Fatal error: Call to a member function assign() on a non-object
Fatalerror:Calltoamemberfunctionassign()onanon-objectinD:\webs\www\web2\application\c...
Fatal error: Call to a member function assign() on a non-object in D:\webs\www\web2\application\controllers\back\indexAction.php on line 28
我刚自己写了一个phpmvc的框架,我在后台做了视图类,采用单例模式,用的是smarty模板,然后在后台对应控制器里边直接使用,将对应数据模型调用之后,出现了这个问题,请问这是为什么?望高手解答,谢谢!
代码如下:
后台视图类
class viewBackLib{
private static $viewBack = null;
public static function getInstance(){
if(self::$viewBack == null){
include 'smarty/Smarty.class.php';
$smarty = new Smarty();
$smarty->template_dir = ROOT.'views'.DS.'manage';
$smarty->compile_dir = ROOT.'public'.DS.'template_c';
$smarty->cache_dir = ROOT.'public'.DS.'cache_back';
$smarty->left_delimiter = '<!-- {';
$smarty->right_delimiter= '} -->';
$smarty->assign('VUrl',ServerName.'/web2/views/manage/');//注册视图路径
self::$viewBack = $smarty;
return $smarty;
}
else{
return self::$viewBack;
}
}
}
这是后台的左侧菜单模型
class menusModel{
public function menuList(){
$menuArr[] = DBLib::fetchAll("select M_id,M_name from ".TABPX."manmenus where M_pId = 0 order by M_order", array());
$menuArr[] = DBLib::fetchAll("select M_id,M_pId,M_name,M_a,M_m from ".TABPX."manmenus where M_pId != 0 order by M_order", array());
return $menuArr;
}
//下拉菜单构成
public function getOptions($seleted=null){
$arr = DBLib::fetchAll("select M_id,M_name from ".TABPX."manmenus where M_pId = 0 order by M_order", array());
foreach ($arr as $rowsCa){
$option[$rowsCa['M_id']] = $rowsCa['M_name'];
}
$reoptions = '';
foreach ($option as $key=>$values){
$seT = '';
if($seleted != null){
if($seleted == $key){
$seT = ' selected="selected"';
}
}
$reoptions .= '<option value="'.$key.'"'.$seT.'>'.$values.'</option>
';
}
return $reoptions;
}
}
最后一个是后台首页控制器
class indexAction{
public function index(){
$views = viewBackLib::getInstance();
$views->display('index.html');
}
public function top(){
$views = viewBackLib::getInstance();
$views->assign('session',$_SESSION);
$views->display('index_top.html');
}
public function left(){
$views = viewBackLib::getInstance();
$views->caching = true;
$views->cache_lifetime = 3600;
if(!$views->isCached('index_left.html')){
/* 获取菜单数组 */
$menuMObj = new menusModel(pdoLib::getInstance());
$arrMenuList = $menuMObj->menuList();
foreach ($arrMenuList[1] as $ddrows){
$ddMenus[$ddrows['M_pId']][$ddrows['M_id']] = $ddrows['M_name'];
$ddlink[$ddrows['M_id']] = '?a='.$ddrows['M_a'].'&m='.$ddrows['M_m'];
}
$view->assign('menuArr',$arrMenuList[0]);
$view->assign('ddMenus',$ddMenus);
$view->assign('ddlink',$ddlink);
}
$view->display('index_left.html');
}
}
求高手指点!万分谢谢!!! 展开
我刚自己写了一个phpmvc的框架,我在后台做了视图类,采用单例模式,用的是smarty模板,然后在后台对应控制器里边直接使用,将对应数据模型调用之后,出现了这个问题,请问这是为什么?望高手解答,谢谢!
代码如下:
后台视图类
class viewBackLib{
private static $viewBack = null;
public static function getInstance(){
if(self::$viewBack == null){
include 'smarty/Smarty.class.php';
$smarty = new Smarty();
$smarty->template_dir = ROOT.'views'.DS.'manage';
$smarty->compile_dir = ROOT.'public'.DS.'template_c';
$smarty->cache_dir = ROOT.'public'.DS.'cache_back';
$smarty->left_delimiter = '<!-- {';
$smarty->right_delimiter= '} -->';
$smarty->assign('VUrl',ServerName.'/web2/views/manage/');//注册视图路径
self::$viewBack = $smarty;
return $smarty;
}
else{
return self::$viewBack;
}
}
}
这是后台的左侧菜单模型
class menusModel{
public function menuList(){
$menuArr[] = DBLib::fetchAll("select M_id,M_name from ".TABPX."manmenus where M_pId = 0 order by M_order", array());
$menuArr[] = DBLib::fetchAll("select M_id,M_pId,M_name,M_a,M_m from ".TABPX."manmenus where M_pId != 0 order by M_order", array());
return $menuArr;
}
//下拉菜单构成
public function getOptions($seleted=null){
$arr = DBLib::fetchAll("select M_id,M_name from ".TABPX."manmenus where M_pId = 0 order by M_order", array());
foreach ($arr as $rowsCa){
$option[$rowsCa['M_id']] = $rowsCa['M_name'];
}
$reoptions = '';
foreach ($option as $key=>$values){
$seT = '';
if($seleted != null){
if($seleted == $key){
$seT = ' selected="selected"';
}
}
$reoptions .= '<option value="'.$key.'"'.$seT.'>'.$values.'</option>
';
}
return $reoptions;
}
}
最后一个是后台首页控制器
class indexAction{
public function index(){
$views = viewBackLib::getInstance();
$views->display('index.html');
}
public function top(){
$views = viewBackLib::getInstance();
$views->assign('session',$_SESSION);
$views->display('index_top.html');
}
public function left(){
$views = viewBackLib::getInstance();
$views->caching = true;
$views->cache_lifetime = 3600;
if(!$views->isCached('index_left.html')){
/* 获取菜单数组 */
$menuMObj = new menusModel(pdoLib::getInstance());
$arrMenuList = $menuMObj->menuList();
foreach ($arrMenuList[1] as $ddrows){
$ddMenus[$ddrows['M_pId']][$ddrows['M_id']] = $ddrows['M_name'];
$ddlink[$ddrows['M_id']] = '?a='.$ddrows['M_a'].'&m='.$ddrows['M_m'];
}
$view->assign('menuArr',$arrMenuList[0]);
$view->assign('ddMenus',$ddMenus);
$view->assign('ddlink',$ddlink);
}
$view->display('index_left.html');
}
}
求高手指点!万分谢谢!!! 展开
1个回答
展开全部
因为函数里要使用函数外的变量 要加global 这样你函数内的$smarty对象才是全局变量$smarty
function a(){
global $smarty;
$a="ee";
$smarty->assign('a',$a);
}
a();
$smarty->display('ce.html');
?>
function a(){
global $smarty;
$a="ee";
$smarty->assign('a',$a);
}
a();
$smarty->display('ce.html');
?>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
威孚半导体技术
2024-08-19 广告
2024-08-19 广告
威孚(苏州)半导体技术有限公司是一家专注生产、研发、销售晶圆传输设备整机模块(EFEM/SORTER)及核心零部件的高科技半导体公司。公司核心团队均拥有多年半导体行业从业经验,其中技术团队成员博士、硕士学历占比80%以上,依托丰富的软件底层...
点击进入详情页
本回答由威孚半导体技术提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询