creocoder / yii2-nested-sets

The nested sets behavior for the Yii framework.
Other
446 stars 129 forks source link

Must be 'Menu' class? #113

Closed gvanto closed 6 years ago

gvanto commented 6 years ago

I have a set of activerecord models that I would like to categorize (only 2 levels deep but possibly more in the future) and thinking of using this nested sets lib ... (to assign my models a category somehow, still need to figure out how, probably a single model->hasOne(category) relationship will do)

I noticed in the Readme it says to create "new Menu([options])" - can this class be called something else (like "Category") whereby I mean can I call the class whatever I like?

Thanks help appreciated, g

Mihai-P commented 6 years ago

Yes, you can name the model in any way you desire. The point of this behavior is that you can attach it to any model and it makes the model work with nested sets.

I use it as product categories, website menus, a restaurant menu (first level are the times of day, the second the categories, the 3rd level the meals), etc. None of my models are actually called "Menu".

gvanto commented 6 years ago

Awesome thanks @Mihai-P this what I was hoping for ...

If you don't mind can I ask how you link your products to product categories? I have a model called BlogSite (resembles a blog/website) which I want to categorize and have it listed under a directory with something like /directory/{cat_level_1} and /directory{cat_level_1}/{cat_level_2} which lists the appropriate blogSites.

Mihai-P commented 6 years ago

I have not done that, but you could try using the sluggable behavior http://www.yiiframework.com/doc-2.0/yii-behaviors-sluggablebehavior.html .

gvanto commented 6 years ago

Cool thanks will check it out.

How if I may ask do you link your products to categories?

On 3 Oct 2017 10:27 pm, "Mihai-P" notifications@github.com wrote:

I have not done that, but you could try using the sluggable behavior http://www.yiiframework.com/doc-2.0/yii-behaviors-sluggablebehavior.html .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/creocoder/yii2-nested-sets/issues/113#issuecomment-333967948, or mute the thread https://github.com/notifications/unsubscribe-auth/AH_CtnSoYXnRzOjNrLO01dKIZe9sSvh4ks5sopitgaJpZM4Pqvjg .

Mihai-P commented 6 years ago

Depends on the requirements, sometimes the products table have a category_id field (when products belong to 1 category only) or with a category_product relationship table when a product can belong to multiple categories.

gvanto commented 6 years ago

OK thanks much thought that might be case just wanted to confirm :D