Is it possible to have a Pager config file in a module's config directory? |
I'm working on a blog module for CI4 and I want to customize the pagination links.
In the doc it says the pager view can be overridden in app/Config/Pager.php, and in module's doc it says you can have a Config directory for your module, but there's not much examples other than how to load a custom config file. Can I have a Pager config file in my module? Something like my-module/Config/Pager.php? I can't make it work. Maybe I need to override the pager service to load my module's config?
I'm back with this problem...
I just reinstalled a new test site with CI 4.0.2 and I'm still stuck with this problem. For my app to use the custom pagination template from my module, I need to edit app/Config/Pager.php because CI won't load my-module/Config/Pager.php. In the debug toolbar, I can see that only APPPATH/Config/Pager.php is loaded. Is this a bug? Did we forget to check if there's a Pager.php file in a module's config directory?
Encountering same issue in 4.6.0 with automatic pagination using CodeIgniter's model.
Config/Autoload PHP Code: public $psr4 = [ App\Model\UserModel PHP Code: class UserModel extends Model { App\Config\Pager PHP Code: public array $templates = [ Admin\Config\Pager PHP Code: public array $templates = [ Admin\Controllers\User PHP Code: $model = model('UserModel'); App\Config\Pager views are loaded instead of those defined in Admin\Config\Pager All module views load fine except for pagination. ![]() Loading the module config before the model gets around the issue... PHP Code: config('Admin\Pager'); But shouldn't Admin\Config\Pager be loaded automatically?
https://github.com/codeigniter4/CodeIgni...es.php#L67
PHP Code: /** Module configs are not autoloaded. Registrars are, so you can make registrar in that module and your config should be overrriden. With Pager config I have not tested this though Example to override App supportedLocales, maybe you can use this approach PHP Code: <?php namespace Modules\Language\Config;
@includebeer How I got around the problem below. Replace "Admin" with your module's namespace.
\Admin\Controllers\BaseController PHP Code: public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { Could not determine why module Pager config is not automatically loaded ![]() Quote:Module configs are not autoloaded. admin/Config/Routes.php gets autoloaded in my module ![]()
Well... $aliases list is config classes which are autoloaded
PHP Code: public $aliases = [ Actually in that case, just add Pager to this list Quote:Actually in that case, just add Pager to this list No obvious effect. Still had to call config('Admin\Pager') before model to make module templates load. Just now realizing admin/Config/App.php is not loaded either (eg: base_url() returns app base, not module base). No point beating that horse ![]() We thought modularization was a slim alternative to multi-app single install.
![]() Opinion: Autoloading modular config for respective classes by default should be an option.
@davis.lasis thanks for referencing registrars. After a fresh night's sleep, that is superior to our previous workarounds.
PHP Code: <?php While digging around CodeIgniter\Config\Factories::getOptions() we spotted "registrar" in code comments, and recalled your mention thereof, sending us down the path. @includebeer This ![]() |
Welcome Guest, Not a member yet? Register Sign In |