开发者

CakePHP hasMany relationship access question

开发者 https://www.devze.com 2023-01-26 16:05 出处:网络
I have 3 models that are related: Folders Files Revisions Folders have many Files. Files have many revision. Files have one folder. Revisions have one file.

I have 3 models that are related:

Folders Files Revisions

Folders have many Files. Files have many revision. Files have one folder. Revisions have one file.

I've setup all my relationships and everything is getting created right in the database. I am trying to edit the scaffolded HTML and have a really basic question: how do I access the revision numbers from the folders view?

That is, I want to print out a table that lists all the files in a folder and all the revisions for each of those files. I am a CakePHP newbie, and I know t开发者_JS百科his is a simple thing, but I'm just not getting it!

I read this page: http://book.cakephp.org/view/81/belongsTo, which instructed me to do something like $this->Profile->find(), but I don't understand where this goes (controller? model? how does this ultimately show up in the view.ctp file?)


To approach your goal only two relationships are required

Folder hasMany File
File hasMany Revision

The other two you set are not correct.Files should beLongsTo folders and revisions beLongsTo files.If you set all relationships correctly,you will get the data you need simply using

$this->Folder->find('all');

0

精彩评论

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