CodeIgniter Forums
Controller method's parameter returns NULL? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Controller method's parameter returns NULL? (/thread-68607.html)



Controller method's parameter returns NULL? - minuit38 - 08-03-2017

Hi all, I've tried pretty much everything and can't get the 'home' page to load with http://localhost but only with http://localhost/home

The code below is a test. 
http://localhost  <= loads the about page
http://localhost/home   <= loads the home page

What could be wrong? The $page variable is supposed to carry "home" but it's not. 

PHP Code:
class Pages extends PublicController
{
    public function 
view($page 'home')
    {

        if (
$page == NULL) {
            
$page 'about';
        } 



RE: Controller method's parameter returns NULL? - kilishan - 08-03-2017

What does your routing look like?


RE: Controller method's parameter returns NULL? - minuit38 - 08-03-2017

Now it looks like this but the behavior is the same. Thanks for having a look :-)



PHP Code:
$routes->setDefaultController('Pages/view');
$routes->get('ajax/(:segment)''Ajax::$1');
$routes->post('ajax/(:segment)''Ajax::$1');
$routes->get('news/(:segment)''News::view/$1');
$routes->get('news''News::index');
$routes->add('(:any)''Pages::view/$1');