$sql = "SELECT * from idea ORDER BY datetime DESC LIMIT 50;"; $result = $pdo->query($sql); if($result->rowCount() > 0 && !empty($result)) // line 6 { foreach ($result as $row) { $id = $row[‘id‘]; $title = $row[‘title‘]; $idea = $row[‘idea‘]; echo ‘<span class="idea" id="‘.$id.‘"><strong style="color: #0081C5">‘ . $title . "</strong> - " . $idea . ‘ <a class="delete" href="#">[Delete]</a></span>‘; } }
一般如果你的sql语句查询出现错误时,没有进行$result 的判断,直接使用$result -> rowCount()会出现这种错误。
Fatal error: Call to a member function assign() on a non-object
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fatal error: Call to a member function assign() on a non-object相关的知识,希望对你有一定的参考价值。
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');
求高手指点!万分谢谢!!!
function a()
global $smarty;
$a="ee";
$smarty->assign('a',$a);
a();
$smarty->display('ce.html');
?>
本回答被提问者和网友采纳
Fatal error: Call to a member function rowCount() on a non-object in /opt/lampp/htdocs/xampp/assets/
以上是关于Fatal error: Call to a member function assign() on a non-object的主要内容,如果未能解决你的问题,请参考以下文章
Fatal error: Call to a member function assign() on a non-object
Fatal error: Call to a member function on a non-object 的2种解决办法
Fatal error: Call to undefined function oci_connect()
PHP Fatal error: Call to a member function query() on a non-object in F 代码如下
Fatal error: Uncaught Error: Call to undefined function gzinflate()