Welcome Guest, Not a member yet? Register   Sign In
Subdirectory Controller Problem
#1

[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?
#2

[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
#3

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB