Welcome Guest, Not a member yet? Register   Sign In
Call to a member function get() on null Error
#4

(This post was last modified: 06-08-2025, 06:15 PM by grimpirate.)

If what you want is a dropdown that shows values in the language you're using here is some sample code:
PHP Code:
<?php

$options 
= [
    'en'  => lang('Choice.en'),
    'es'    => lang('Choice.es'),
];

echo 
form_dropdown('language'$options); 

Then in your app/Languages you would create subdirectories for each of your languages let's say your supportedLocales was en, es. You would then create a file called Language.php in each directory.

In app/Languages/en/Language.php
PHP Code:
<?php
return [
    'en' => 'English',
    'es' => 'Spanish',
]; 

In app/Languages/es/Language.php
PHP Code:
<?php
return [
    'en' => 'Ingles',
    'es' => 'Español',
]; 

CodeIgniter takes care of determining the language you want displayed (based on user's browser settings) and substitutes accordingly.

Then you submit/validate however you feel appropriate, push into your session, and your code in your BaseController's initController method for setting the language becomes:
PHP Code:
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        
$request->setLocale(session('language'));
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
// Preload any models, libraries, etc, here.

        // E.g.: $this->session = service('session');
    

Reply


Messages In This Thread
RE: Call to a member function get() on null Error - by grimpirate - 06-08-2025, 06:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB