CodeIgniter Forums
DefaultMethod in Route file not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: DefaultMethod in Route file not working (/showthread.php?tid=81269)



DefaultMethod in Route file not working - pikato - 02-11-2022

Hi, The default method in the routes file setting does not seem to be working. Can someone please help?

* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Console');
$routes->setDefaultMethod('portfunc');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);


<?php

namespace App\Controllers;

class Console extends BaseController
{
    public function index()
    {
        echo "Console";
    }
    public function portfunc() {
        echo "Console port";
    }
}

Correct me if I'm wrong, I think, the controller should point to the default function set as portfunc().
Kindly intervene. Thanks

<?php

namespace App\Controllers;

class Console extends BaseController
{
    public function index()
    {
        echo "Console";
    }
    public function portfunc() {
        echo "Console port";
    }
}





   public function index()
    {
        echo "Console";
  



RE: DefaultMethod in Route file not working - kenjis - 02-12-2022

It seems this is a bug.

I recommend you set:
PHP Code:
$routes->get('/''Console::portfunc'); 



RE: DefaultMethod in Route file not working - pikato - 02-12-2022

(02-12-2022, 02:17 AM)kenjis Wrote: It seems this is a bug.

I recommend you set:
PHP Code:
$routes->get('/''Console::portfunc');


I agree with you @kenjisI think setting the route explicity does the job