![]() |
Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter - 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: Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter (/showthread.php?tid=92446) |
Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter - 4usol - 02-08-2025 Hi, to load translation-files and create some dynamic content, i add the language service to the _construct of my own library. Code: "function __construct(){ ... $this->lang = service('language');" ... }" Now i want to load a language file by calling my lib inside a view-file in this way Code: "$ci->mytools->lang->load(filepath', $ci->mytools->request->getLocale(),true)" The result is the error message: "Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter\View\View" What i do wrong - how i cann load a language file on each point i want? RE: Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter - ozornick - 02-09-2025 No way, this is a system method. You can replace service('language') in Config/Services.php and add the desired methods. https://github.com/codeigniter4/CodeIgniter4/blob/c430f347200ec3a505cb48233f577edef5a1de5c/system/Language/Language.php#L237 RE: Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter - InsiteFX - 02-09-2025 Where are you getting the $ci from this looks like CodeIgniter 3 code. RE: Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter - 4usol - 02-09-2025 is there no way to load a translation file in a view? RE: Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter - JustJohnQ - 02-10-2025 Do you want to load the whole file to be used in a view or are you looking to use language specific strings in your view? The most obvious way to use a language string is something like this: PHP Code: <?= lang('General.Actions') ?> Where there is an existing file in the Language/en folder with the name 'General.php'. Content would be: PHP Code: <?php |