S
S
sanex33392015-04-11 12:44:37
JavaScript
sanex3339, 2015-04-11 12:44:37

What is the best way to change module architecture?

So:
There is a module that draws on the category page 'checkboxes' (actually these are links) to filter the result, when clicking on them, displays the filtered model data in the specified view, where the user can display them in a convenient way.

The task has already been implemented for the yii2 framework.
When installing the module, the user needs to specify in his controller and in the view where the data should be displayed - 3 module methods with different settings:
in the controller - initial module settings - model, caching settings, alias to ajax view (filtered data is delivered to it), which renderPartial() will be sent to the main view of the controller
in the main view - we indicate which checkboxes we draw, i.e. by what properties of the model and by what values ​​we will filter the data
in the main view - by the method we indicate the place where we will render the ajax-view with data

Visually, it looks like this: www.youtube.com/watch?v=Vah2j5WzXIs

Now about the architecture:
When loading or updating the page, the module call point is, respectively, the module method (where we specify the model and module settings) called in the controller, then from the module method we knock on the module controller, from where we go to the module class, in which we collect query and get data from models that we pass back to the module controller, where we then output them to the ajax view.
Most importantly, all module settings are specified when the module is called in the user controller.

Now the problem:
When clicking on the checkbox, we ajax knock directly on the controller of the module itself, and then the problem arises - get the previously specified module settings , and among the settings there are also objects (model, for example).

At the moment, when I first call the module, among other things, I shove all the necessary settings into an array that I encrypt (using the yii2 encryptByKey () method with the cookieValidationKey key, which is unique for each yii2 application), and after that I put the array into the session. Accordingly, when I make an ajax request to the module controller, I take all the settings from the session, decrypt them with the same key, and then I work as usual, get the filtered data and output it to the ajax view.

Actually, I would like to know - how to change the architecture of the module in order to receive the module settings during an ajax request to the module WITHOUT using sessions, cookies, databases and local storage?
Condition - module settings must be specified in the controller in which this module is called.

I tried the option - to hammer ajax into the controller from which the module is called, i.e. we dug in there and re-received its settings, but there were terrible jambs with rendered views (in the main view, the main view was rendered again

)
8176af2b07.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-04-13
@sanex3339

We look at the module definition www.yiiframework.com/doc-2.0/guide-structure-modul... all of these are an "independent" application unit with its own controllers, models, components. We look at the definition of your module "There is a module that draws on the page of the category 'checkboxes'". Already in the first sentence, you define the widget www.yiiframework.com/doc-2.0/guide-structure-widge... It's just "drawing".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question