Re: newbie
| From: | Matthew Weier O'Phinney | Date: | Tue, 26 Jul 2005 14:17:51 +0000 |
| Subject: | Re: newbie | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12862@lists.php.net to get a copy of this message | ||
* Patrick Roane <fojomo@sbcglobal.net>:
> I'm on ch 7 of the php5/myswl/ecomm book.
>
>
> There is an error I get whenever I press the 'Edit
> Categories' button:
>
> Fatal error: Cannot use object of type DB_result as
> array in
> c:\customfurniture\templates_c\%%F9^F97^F97AE06E%%admin_categories.tpl.php
> on line 49
Sounds to me like you're either (1) trying to access an object using
array-style syntax in Smarty, or (2) you're passing the wrong item to
the template.
In the case of (1), you probably retrieved the results of a DB call as
an object (perhaps by setting DB_FETCHMODE_OBJECT), and passed the
object to the template. Then you used syntax like:
{$result.name}
to print out the 'name' field of the result. However, that syntax is for
accessing elements in an array; the correct syntax would be:
{$result->name}
which would access the name property of the object.
In the case of (2), you may have performed a query that returned a
resultset, but you didn't pull a record or set of records from the
resultset to pass to the template. For example:
$results = $db->query($sql);
$tpl->assign('result', $results);
when you should have done something like:
$results = $db->query($sql);
$row = $results->fetchRow(DB_FETCHMODE_ASSOC);
$tpl->assign('result', $row);
Good luck!
--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/