Welcome Guest, Not a member yet? Register   Sign In
sub controllers
#1

[eluser]hailwood[/eluser]
I am wondering if it is possible in code igniter to have sub controllers?

By this I mean.

I have my message controller.

inside the controller I have "pages(functions)" called sent/settings/view/ ect

so

Quote:example.com/messages/sent
example.com/messages/settings
example.com/messages/view

this works fine.

But now I want to add one called lists,

This is ok except.

The lists one needs to have its own methods. such as create/edit/view

So the url would be

Quote:example.com/messages/list/create
example.com/messages/list/edit
example.com/messages/list/view

What is the best way to handle this situation?

I have a lists model so I could have

Code:
class Messages extends Controller {
  ...
  function list($func){
    $this->load->model('lists');
    $this->lists->$func();
    ...
  }
  ...
}

But I really dont want to do it that way. as it makes it difficult for handling params and doing other actions.

I could do
Code:
class Messages extends Controller {
  ...
  function list($func){
    $this->load->model('lists');
    switch($func):
      ...
    endswitch;
    ...
  }
  ...
}

But I dont want to do that either as the function could get quite large.
#2

[eluser]WanWizard[/eluser]
No, but you can create a folder in Controllers called 'Messages', and in there create a Controller called 'List'. If that has a method called 'create', "example.com/messages/list/create" works.

Note that you can only go one level deep, CI doesn't support any more levels.
#3

[eluser]hailwood[/eluser]
Can I have both a folder and a controller with the same name?
#4

[eluser]pickupman[/eluser]
You can use [url="http://ellislab.com/codeigniter/user-guide/general/routing.html"]routes[/url] to simulate this type of behaviour. You can create a lists controller and use a route like
Code:
$routes['messages/list/(:any)'] = 'list/$1';

This makes any link with messages/list/(something) actually run the list controller and the (something) method. Also you may want to check out [url="http://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home"]Modular Extensions[/url] for HMVC structure and cross loading controllers.
#5

[eluser]mike7418[/eluser]
It is possible IF you use iframes for the different blocks.
#6

[eluser]pickupman[/eluser]
Iframes would load any remote or local page. The iframe blocks don't load based on the URI in the address bar but rather than the source attribute of the tag.




Theme © iAndrew 2016 - Forum software by © MyBB