Welcome Guest, Not a member yet? Register   Sign In
set404Override - setLocale not working?
#1
Question 
(This post was last modified: 03-22-2020, 05:21 PM by haugli92.)

Hi!

I'm just wondering why the controller set in set404Override() not listening to the selected locale. Is this a feature or a bug?
Any other controller is working properly.

app/Config/Routes.php
PHP Code:
$routes->set404Override('App\Controllers\Error::error_404'); 

app/Controllers/Error.php
PHP Code:
<?php namespace App\Controllers;
 
class 
Error extends BaseController {
  public function error_404() {
    echo $this->request->getLocale(); //Output: no (Norwegian)
 
    echo view('_includes/header_clean'); // Outputs data from en (English)
    echo view('main/main');              // Outputs data from en (English)
    echo view('_includes/footer_clean'); // Outputs data from en (English)
 
    echo $this->request->getLocale(); //Output: no (Norwegian)
  }

Reply
#2

Bump? No idea?
Reply
#3

Trying again. Bump
Reply
#4

What do you mean your view files output data in English? Are the views supposed to be multilingual?
Reply
#5

(This post was last modified: 10-19-2020, 01:16 AM by haugli92.)

(09-28-2020, 02:24 AM)paulbalandan Wrote: What do you mean your view files output data in English? Are the views supposed to be multilingual?

All text in the view files is stored in the language files.
When language is selected all text should be read from that language.

It works on any page but, App\Controllers\Error::error_404

It seems to read browser's preferred language when hitting this page. Ignoring the selected language.
Reply
#6
Sad 

(10-19-2020, 01:15 AM)haugli92 Wrote:
(09-28-2020, 02:24 AM)paulbalandan Wrote: What do you mean your view files output data in English? Are the views supposed to be multilingual?

All text in the view files is stored in the language files.
When language is selected all text should be read from that language.

It works on any page but, App\Controllers\Error::error_404

It seems to read browser's preferred language when hitting this page. Ignoring the selected language.
I have the same problem, have you been able to solve it? Huh
Reply
#7

I found a different solution:
config\routes.php:
PHP Code:
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override(function()
{
    $header = array(
    'css' => 'nodata',
    'title' => 'Page not found | wdeda'
    );
    
    
echo view('templates/headerr'$header);
    echo view('content/error_404');
    echo view('templates/footerfb');
    }); 

There is a controller:
PHP Code:
<?php namespace App\Controllers\General;
    
    
// 200508
    
    
use CodeIgniter\Controller;
    
    
class Errors extends Controller {
        
    
public function index() {

        $header = [
            'css' => 'nodata',
            'title' => 'Page not found | wdeda'
        ];
    
        
echo view('templates/headerr'$header);
        echo view('content/error_404');
        echo view('templates/footerfb');
    
        
}

        
    
public function nodata() {


        $header = array(
            'css' => 'nodata',
            'title' => 'Invalid search argument | wdeda'
        );
        echo view('templates/headerr'$header);
        echo view('content/nodata');
        echo view('templates/footerfb');

    }

    public function nodatabkps() {
        $header = array(
            'css' => 'nodata',
            'title' => 'Search Results | wdeda'
        );
        echo view('templates/headerr'$header);
        echo view('content/nodata');
        echo view('templates/footerfb');
        
    
}

And finally, the view:
PHP Code:
<!-- 20200524 -->

<
div class="content-container">
<
div class="message">
<
img title="Oops" src="/assets/img/common/wd-20200416-oops.png"/>
<
span class="msgerror">ERROR 404page not found.</span>
<
h2>
What the f***!<br>
Houstonwe have a problem here.
</
h2>
<
h4>Sometimes this can happenSorry for the inconvenience.</h4>
</
div>
<
div class="links">
<
p><a href="http://localhost">Return to Homepage</a></p>
<
p><a href="mailto://[email protected]">Contact us to report a problem.</a></p>
</
div>
</
div
Reply
#8

(This post was last modified: 08-26-2021, 02:07 AM by InsiteFX.)

I think you need to call the Controllers initController.

PHP Code:
/**
* Constructor.
*
* @param RequestInterface  $request
* @param ResponseInterface $response
* @param LoggerInterface  $logger
*/
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
{
    // Do Not Edit This Line
    parent::initController($request$response$logger);

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

    // E.g.: $this->session = \Config\Services::session();




Add that and see if it fixes it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB