我對這個站點和學習PHP都很陌生。我使用Darie和Bucica開始的PHP5和MySQL電子商務從新手到專業創建一個電子商務網站。我相信迄今爲止我遇到的一些錯誤是由於更新的數據庫(MDB2)。除了這個之外,我已經能夠通過每一個錯誤。該代碼應該使用Smarty從我的數據庫中提取部門列表。PHP和Smarty錯誤:試圖獲取非對象的屬性
我在最後一行發生錯誤「嘗試獲取非對象的屬性」。我有一種感覺,它與is_array()函數有關。
<?php $_smarty_tpl->tpl_vars["load_departments_list"] = new Smarty_variable("departments_list", null, null);?>
<table border="0" cellpadding="0" cellspacing="1" width="200">
<tr>
<td class="DepartmentListHead"> Choose a Sport </td>
</tr>
<tr>
<td class="DepartmentListContent">
<?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']['i']);
$_smarty_tpl->tpl_vars['smarty']->value['section']['i']['name'] = 'i';
$_smarty_tpl->tpl_vars['smarty']->value['section']['i']['loop'] = is_array($_loop=$_smarty_tpl->getVariable('departments_list')->value->mDepartments) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
如果還有其他東西需要幫忙解答,請告訴我!請儘可能描述,如果可能,請使用我的代碼顯示解決方案。謝謝你的幫助! -Drew
這是一本書的代碼? `unset($ _ smarty_tpl-> tpl_vars ['smarty'] - > value ['section'] ['i']);`移除您在最後兩行嘗試訪問的變量。 – thetaiko 2011-01-08 22:21:37
我認爲這部分是從.tpl文件編譯而不是直接在本書中編譯的。無論如何,它並不是我個人添加的。感謝您指出了這一點。我會看看那個! – DrewInPB 2011-01-09 01:10:32