Config/Services getSharedInstance returns an empty array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Config/Services getSharedInstance returns an empty array (/showthread.php?tid=80300) |
Config/Services getSharedInstance returns an empty array - BYOOS - 10-15-2021 hello devs I have a problem with the codeIgniter4.1.4 services in the controller I have the following code, in Config/Services getSharedInstance returns an empty array, namespace App\Controllers; use Config\Models; use Config\Services; use Config\ViewFrontend; abstract class Frontend extends App { public $lang; public function __construct() { parent::__construct(); $this-> language = \ Config \ Services::language()->get (); $this->lang = $this->language['code']; .... } } in the service /root/App/Config/Services.php I have class Services extends CoreServices { public static function language (string $locale = null, bool $getShared = true): Language { if ($ getShared) { return static::getSharedInstance ('language', $locale) -> setLocale ($locale); } $ local =! empty ($locale)? $locale: static :: request () -> getLocale (); return new Language ($locale); } } // in the service /root/App/Libraries/Language.php I have namespace App \ Libraries; use \ CodeIgniter \ Language \ Language as CI_Language; use App \ Models \ Languages; private $DBlanguage; class Language extends CI_Language { public function get (): array { return (array) $this->DBlanguage; } } Thanks for your help Gabriel RE: Config/Services getSharedInstance returns an empty array - kenjis - 10-15-2021 (10-15-2021, 01:17 AM)BYOOS Wrote: // in the service /root/App/Libraries/Language.php I have It seems $this->DBlanguage is an empty array. RE: Config/Services getSharedInstance returns an empty array - paliz - 10-15-2021 we have these layers controller service entity model migrtation seeder for problem use config not service use service like that PHP Code: <?php namespace Modules\Auth\Config; PHP Code: <?php namespace Modules\Auth\Controllers; RE: Config/Services getSharedInstance returns an empty array - BYOOS - 10-22-2021 Good evening, thank you for your very interesting answers, I specify that the proposed code is an extract of a more important application and the author uses the end-to-end services, I dry like an old squid... to note PHP 8.0.11 codeigniter 4.1.4 app https://github.com/khodakhah/nodcms |