Welcome Guest, Not a member yet? Register   Sign In
Remove segment from url in multi language site

(This post was last modified: 02-22-2021, 08:32 AM by eleumas.)

(02-22-2021, 06:05 AM)demyr Wrote: It looks like you are trying to add and view the result within the same method (It/Main::article). Have you tried seperating them? Plus, can you see any response data from your controller, I mean for example:

PHP Code:
$slug = \Config\Services::request()->uri->getSegment(2);


Hi @demyr!
I have a view called blog with categories and articles for each category.

blog method:
PHP Code:
    public function blog()
$data['title'] = '';
$data['metaDescription'] = '';
$data['articles'] = $this->articlesModel->orderBy('id''DESC')->where('status'1)->findAll();
$data['categories'] = $this->categoriesModel->where('lang''it')->findAll();


article method:
PHP Code:
public function article()
$slug = \Config\Services::request()->uri->getSegment(2);
    $data['article'] = $this->articlesModel->where('slug'$slug)->first();
    $dataArticle $data['article'];
    $data['title'] = $dataArticle['meta_title'];
    $data['metaDescription'] = $dataArticle['meta_description'];
    $data['images'] = $this->imagesGalleryModel->where('article_id'$dataArticle['id'])->findAll();
    // // //
    $data['latestArticles'] = $this->articlesModel->orderBy('id''DESC')->where('status'1)->findAll(5);
    // // //
    $builder $this->db->table('tbl_articles');
    $data['hitsArticles'] = $builder->get(10);
    // // //
    $builder $this->db->table('tbl_articles');

    return view('article'$data);

PHP Code:

// GOOD WITH WORD ARTICLE IN LINK: mysite.com/it/article/slug
// $routes->add('(:any)/it/article', 'It/Main::article/$1');
// $routes->get('{locale}/article/(:any)', 'It/Main::article');


The error is the same: Trying to access array offset on value of type null

I have this code in another site with one language, CI 4.0.4 and PHP 7.4 and all works fine!

I tried your code and the uri segment is correct i can see the answer from my controller.

Thanks for help me!


Messages In This Thread
RE: Remove segment from url in multi language site - by eleumas - 02-22-2021, 08:04 AM

Theme © iAndrew 2016 - Forum software by © MyBB