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');
}
}
求高手指点!万分谢谢!!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询