caching - When is module rendered in drupal? -
i newcomer in drupal, , want make custom module in drupal8. have developed module, there problems solve.
the module displays parameter value when page containing module shown users.
for example, connect http://localhost/drupal/?keyword=banana , module displays "banana".
but after above, when connect http://localhost/drupal/?keyword=apple again, module displays "banana" too.
in other words, module works when page containing module shown firstly , works wrong when connect secondly, thirdly , on.
i have tested , build() method in module called once. so, think module rendered once when connect page , can't rendered after first.
also, think can problem related cache, set admin/configuration/performance/cache "no-cache".
i not sure possible display "apple" after "banana" displayed module.
please me , let me know more details...
thanks.
there couple of possible solutions depending on constraints: disable cache particular page, or use routing wildcards.
you can disable cache on particular page using page cache kill switch service, trigger in controller:
\drupal::service('page_cache_kill_switch')->trigger();
this disable cache particular request, won't effect of seeing stale content.
a better solution, if possible, use routing parameters instead of parameters. allow separate urls (for example page/banana, page/apple etc.) cached , still show contents you'd them to. example, in module.routing.yml file:
mymodule.route: path: '/path/{parameter}' defaults: _controller: '\drupal\mymodule\controller\mymodulecontroller::page' _title: 'my module page' requirements: _permission: 'access content'
the {parameter} parameter can accessed in controller so:
public function page($parameter) { return ['#markup' => $parameter]; }
more information: https://www.drupal.org/node/2186285
Comments
Post a Comment