开发者

CakePHP: Few questions about models, controllers an retrieving data

开发者 https://www.devze.com 2022-12-17 19:13 出处:网络
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.

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 o开发者_如何转开发ut.

Thanks!


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']


Well, at the start you could do:

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

That'll save you some typing.

0

精彩评论

暂无评论...
验证码 换一张
取 消