CodeIgniter Forums
Subdirectory Controller Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Subdirectory Controller Problem (/showthread.php?tid=13218)



Subdirectory Controller Problem - El Forum - 11-14-2008

[eluser]Kyle Wiebers[/eluser]
I'm building my first website with CodeIgniter and it's very easy so far. However I want to create a url like localhost/MU/events/rooms/roomname, where roomname changes with the room the user selects. I have a function rooms in the events controller that takes an argument, but when trying to access the main page, localhost/MU/events/rooms CI throws an error that I was missing an argument.

My code looks like this:
Code:
function rooms($room)
    {
        if(isset($room)) {
            switch($room) {
                case 'name':
                    $data['content'] = '<p>Room Name</p>';
                    break;
            }
        } else {
            $data['content'] = '<p>Test</p>';
        }
        $this->load->view('header');
        $this->load->view('masthead');
        $this->load->view('menu');
        $this->load->view('event-menu');
        $this->load->view('home-side');
        $this->load->view('content',$data);
        $this->load->view('footer');
        
    }

Is there anyway to eliminate the error on the page?


Subdirectory Controller Problem - El Forum - 11-15-2008

[eluser]julgus[/eluser]
Hi
instead of using isset I would prefer $this->uri->segment(n) where n is the number of the uri segment. This contains the value if it exists of false if nothing is specified.

You have to load the uri class.

Regards


Subdirectory Controller Problem - El Forum - 11-15-2008

[eluser]Rick Jolly[/eluser]
Code:
function rooms($room = false) {
...



Subdirectory Controller Problem - El Forum - 11-15-2008

[eluser]Kyle Wiebers[/eluser]
Thanks for the help. I love the CodeIgniter base, it is by far the easiest and best supported framework I've ever used.