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

[eluser]Chad Tomkiss[/eluser]
Hi,

I have just started working with CodeIgniter, and firstly, what a framework!

However, I am a little curious as to whether I am setting the controllers up correctly.

I am comfortable with having:

example.com/community/team

and having

Code:
class Community extends Controller {

    function Community()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('community/index');
    }

    function team()
    {
        $this->load->view('community/team');
    }
}


However, what would be the best way of achieving:

example.com/community/resources/screensavers


Also, as functions cannot contain dashes, how would you achieve urls such as
example.com/community/meet-the-team for example.

I have looked through the forum/searched google, but I cannot find a solution that is viable.


Kind regards,

Chad
#2

[eluser]Thorpe Obazee[/eluser]
[quote author="Chad Tomkiss" date="1246628928"]

Also, as functions cannot contain dashes, how would you achieve urls such as
example.com/community/meet-the-team for example.

I have looked through the forum/searched google, but I cannot find a solution that is viable.


Kind regards,

Chad[/quote]

I searched the forums and found these:

http://ellislab.com/forums/viewthread/114539/
http://ellislab.com/forums/viewthread/102725/
#3

[eluser]Chad Tomkiss[/eluser]
Hi bargainph,

Thank you for your reply.

I had seen the thread, and I did think of

Code:
function resources($page)
    {
        if ($page != NULL)
        {
            $this->load->view('community/resources/$page');
        }
        else
        {
            $this->load->view('community/resources');
        }
    }

but I was not sure if this was the best way.


Kind regards,

Chad
#4

[eluser]xwero[/eluser]
The dashes problem only kicks in if the dashed segment is a controller or method name. If the dashes are in the parameter(s) you have no problem.
#5

[eluser]Chad Tomkiss[/eluser]
I am not sure if the above code is going to work.

As if you were to have

resources/page/page2/page3

then it would seem long winded to pass in $page1, $page2, $page3 to the function.

Would it be advisable to take the approach of just having 1 class 1 function.

So rather than community/resources/desktop/widgets

having

community/resources
community/desktop
community/widgets

and then just link to widgets in the desktop view etc?


Kind regards,

Chad
#6

[eluser]slowgary[/eluser]
Any way will work, use whatever you feel more comfortable with. Maybe you should consider NOT using a community controller, but instead putting your controllers into a community subfolder.

Then your controllers could be team and resources. This would allow you to have something like:
Code:
team/contact
team/members/george

resources/widgets/sms
resources/desktop/screensavers
resources/desktop/icons

Just another idea to add to the pile. Welcome to the forums Smile




Theme © iAndrew 2016 - Forum software by © MyBB