There are for example two modules - a product catalog and seo. All this is displayed in the admin panel on one page, i.e. each product has its own characteristics and seo description. All this as it is necessary to check and save. But the tables are different, hence the model. Those. first product model and second seo. Each has its own field of course. So the question arises of shoving everything into one general form and then resolving or immediately sending each form to your URL (ajax is saved, so you can do it asynchronously). What do you advise ?
- Should seo behevior put? - fedornabilkin
- Well, this is a variant of seo, and so anything can be there. This is just as one of the simplest examples. - Imperfect
|
1 answer
it is possible to transfer two models in the controller in view, and saving them to be done inside a transaction. Or make a separate model in which to put all the fields of both models, validate them. And already inside this model, make the save method, which decomposes the data on the target AR and saves them in a transaction.
- Thanks, the problem is that the modules about each other do not know anything and should not in fact. Therefore, you probably have to write a wrapper for the validator. - Imperfect
- This is the meaning that each AR is clear (although they don’t know, they know, the reports are zhezh), but a third model connects them and implements business logic between them. This is just good practice. slides.rmcreative.ru here's an example recording of the webinar "Yii2 structure of a large project" - Kirill Kikimov
- Thanks, see what's there. - Imperfect
|