Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assigning value of $array.$index->get_method() to variabl

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jkramer@billitco.com
Smarty n00b


Joined: 06 Feb 2015
Posts: 1

PostPosted: Fri Feb 06, 2015 7:43 pm    Post subject: Assigning value of $array.$index->get_method() to variabl Reply with quote

In my TPL file I have an loop like so:

{foreach from=$vehicles item=vehicle}
{assign var="vehicle_id" value=$vehicle->get_vehicle_id()}
{assign var="lease" value=$leases_by_ids.$vehicle_id}
{assign var="leasedate" value=$lease->get_date()}
{/foreach}

*Note:
$vehicles is an array of objects
$leases_by_ids is a array of objects

When executed I get "...called on a non-object".. ideas? Syntax?

Please and thank you.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Feb 07, 2015 3:34 am    Post subject: Reply with quote

http://www.smarty.net/docs/en/language.function.foreach.tpl
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Feb 07, 2015 11:48 am    Post subject: Reply with quote

The error message did tell you the failing method. Then you know the variable which is not an object as expected.

Best guess is that the value of $vehicle_id points to a none existing element of array $leases_by_ids.


The following would be also valid code:
Code:
{assign var="leasedate" value=$leases_by_ids[$vehicle_id]->get_date()}

or

{assign var="leasedate" value=$leases_by_ids[$vehicle->get_vehicle_id()]->get_date()}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP