Re: [PHPTAL] How do I access array keys?

2009-06-18 Thread Tjerk Meesters
Hmm we've seen this mistake being made a lot ;-) would it help if this
was documented under, like, "things to consider when using php:
modifier"? :)

On 6/18/09, Kornel Lesiński  wrote:
> On 18-06-2009 at 15:42:14 Igor Sverkos
>  wrote:
>
>> If you don't have an object, just an array - how do I access a simple
>> array key?
>
> With php: modifier you have to use [] for arrays, and . for objects.
>
>> Template:
>> =
>> [...]
>> 
>> 
>> 
>> 
>>
>>
>> The first td-row will work.
>>
>> The second row will throw a "Trying to get property of non-object..."
>> notice.
>
> Use item['date']
>
> item.date is only for objects, and will not work with arrays.
>
> --
> regards, Kornel
>
> ___
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>


-- 
--
Tjerk

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] How do I access array keys?

2009-06-18 Thread Kornel Lesiński
On 18-06-2009 at 15:42:14 Igor Sverkos  
 wrote:


If you don't have an object, just an array - how do I access a simple  
array key?


With php: modifier you have to use [] for arrays, and . for objects.


Template:
=
[...]






The first td-row will work.

The second row will throw a "Trying to get property of non-object..."  
notice.


Use item['date']

item.date is only for objects, and will not work with arrays.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] How do I access array keys?

2009-06-18 Thread Igor Sverkos
Hi,

If you don't have an object, just an array - how do I access a simple array 
key? 
In TAL, i would just write "array/key", but with modifier, it won't work.

For example:

PHP:

[...]
$data = array();
foreach ($db->fetchRow() as $row){
$item = array(
'name' => $row['name'],
'date' => $row['date']
[...]
);

$data[] = $item;
}

$tpl->set('data', $data);


Template:
=
[...]






The first td-row will work.

The second row will throw a "Trying to get property of non-object..." notice.


-- 
Regards,
Igor



___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal