Custom Config per presenter or class?
- mr.bremm
- Member | 3
Hello,
Within a presenter I'm using a factory to create controls via multiplier.
The factory is registered as service, database and caching is injected via
constructor.
Question:
How do I GET config parameters, perhaps by class or presenter name?
SuperControl:
p1: ptest
I just need the config params, not a full extension (I guess)
so far I have:
services:
- App\Presenters\SuperControlFactory
Thanks for your advice!
- dkorpar
- Member | 136
you can pass config to SuperControlFactory
parameters:
SuperControl:
p1: ptest
services:
- App\Presenters\SuperControlFactory(%SuperControl%)
class SupperControlFactory
{
public function __construct(array $config, SomeService $service)
{
}
}
see https://doc.nette.org/…introduction#…
Last edited by dkorpar (2019-03-28 22:47)
- mr.bremm
- Member | 3
Yes, that works; thanks for your reply!
I'm not used to the easy way by default anymore, let alone the super easy way a
la nette :)
--
Also, something similar was one of the first things I've tried without success
at first, which kept me looking through everything (and learned a lot). Error
was the order; $db and $cache was in place, I've simply added the $config at the
end; old habit, but how should the container kow ..
On my way I found other solutions as well, e.g.
services:
- App\Presenters\SuperConfig(%superApp%)
to inject the “known” config class via constructor, which can read from
file or db.
I've noticed, that all %parameters% get copied; Makes sense for most cases, but
didn't like that for this project.
--
Ultimately, when a config gets too complex its a good sign that it is actually a
model.
So, now there is a proper model in place, including ConfigManager for all things
I need including neon params.
–
Nette? Easy! Recommend new Namespace: SuperNette g :)
Thanks again,
Cheers,
Martin.