CodeIgniter Forums
conflict with method name - 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: conflict with method name (/showthread.php?tid=78675)



conflict with method name - eleumas - 02-23-2021

Hi! i use localization in CI 4.1.1. I have a controller for each language and inside any controller there is a method called blog.

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

        echo 
view('blog'$data);
    } 

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

        echo 
view('blog'$data);
    } 

My routes:

PHP Code:
$routes->add('{locale}/blog''It/Main::blog');
$routes->add('{locale}/blog''En/Main::blog'); 

The result is always the same..it is called only the method blog in "italian controller". 
Codeigniter show the first route found, so in this case for the "italian controller".

Thanks for the support.


RE: conflict with method name - iRedds - 02-23-2021

"You either take off the cross or put on your panties."(с)

From a framework perspective, you are defining the same URL mask.
Choose the right way.
PHP Code:
$routes->add('{locale}/blog''Main::blog');
// or
$routes->add('it/blog''It/Main::blog');
$routes->add('en/blog''En/Main::blog'); 



RE: conflict with method name - eleumas - 02-24-2021

(02-23-2021, 09:39 PM)iRedds Wrote: "You either take off the cross or put on your panties."(с)

From a framework perspective, you are defining the same URL mask.
Choose the right way.
PHP Code:
$routes->add('{locale}/blog''Main::blog');
// or
$routes->add('it/blog''It/Main::blog');
$routes->add('en/blog''En/Main::blog'); 

Hi @iRedds. Thank for reply.

 if I use your route, for example this:
PHP Code:
$routes->add('it/blog''It/Main::blog');
$routes->add('en/blog''En/Main::blog'); 

the page is correct but the main.php is not traslate in English.
Please, watch my screen: https://demo.samuelesantoni.com/host/route-blog.png

Thanks for help me.


RE: conflict with method name - iRedds - 02-24-2021

Perhaps you include the template (main.php) from the IT directory. I don't know how your code works. =)