tags:

views:

78

answers:

2

Hello,

Again me. I was using for a bit long time KohanaPHP and just can't get familiar with CakePHP, but working with it it's a pleasure for me.

First of all, I retrieve data from model, send it via controller to view and now got question. Do I really need to use following syntax of data in foreach loop?

$item['Model']['field']

It's a bit strange for me that I cannot use simply:

$item['field']

Second question... I need to use text core helper. Can I use it in view? I'm asking cause I got error about trying to use on a non-object.

I'm sorry for such newbie questions, but I was out of the coding game for over three years (worked as teacher) and it's really hard to get it sorted out.

Thanks!

A: 

Well, at the start you could do:

$model = $item['Model'];
$field1 = $model['field1'];
$field2 = $model['field2'];
..etc...

That'll save you some typing.

Mr-sk
Right. Didn't thought about this syntax. Thanks!
Johannes
No problem. As for the second part of your question, not sure. heh, sorry.
Mr-sk
The second part is solved. Oh my God... KohanaPHP made me crap, not programmer :-( I forgot to put var $helpers = array('Text', 'Html'); in the controller... Please, no comments :-) Thanks for your time!
Johannes
+3  A: 

the reason you should be using the longer version;

$item['Model']['field']

is for when you're working with models that have associations. say in this case 'Model' belongs to a 'User', you'd be able to work with that mode's user data more clearly:

$item['User']['field']

Adam
Thanks for mading it clear for me.
Johannes