docs icon indicating copy to clipboard operation
docs copied to clipboard

Are we free to put models in any folder location?

Open developedsoftware opened this issue 3 years ago • 5 comments

I realise documentation is not complete and yii3 is still in development. I am just trying to plan a migration from yii2 to yii3 and the only thing I cannot seem to work from this project is where I stick my "models"

Apologies if this is a stupid question. Very much have my Yii2 hat on.

Is there a recommended directory structure?

developedsoftware avatar Mar 29 '21 16:03 developedsoftware

My personal approach: keep controller, models and views close together. General Models in a separate folder Models.

I would like to know a recommended or standardized way as requested though.

Mister-42 avatar Mar 29 '21 16:03 Mister-42

I imagine we can put them anywhere. But I agree some structure and keeping them together is best.

Do you seperate your business logic into folders like “Blog” and then have controllers, models and views under this directory or in subdirectories ?

developedsoftware avatar Mar 29 '21 16:03 developedsoftware

Since I have URLs like https://www.domain.tld/category/page I placed files like this:

Control
 - Controller.php
 - Category
   - page.php (view)
   - page
     - AR.php
     - Model.php
Models
 - GenericModel.php

I'm sure it's not perfect, but works alright for me. I can always find the files fast I need to edit.

Mister-42 avatar Mar 30 '21 09:03 Mister-42

@Mister-42 approach is alright. That should be added to yiisoft/docs.

samdark avatar Mar 31 '21 20:03 samdark

See https://github.com/yiisoft/app/discussions/238

samdark avatar May 11 '22 21:05 samdark