Controller structure

#1
[eluser]vps4[/eluser]
My site's navigation like this

Code:
admin
        A
            A1
            A2
                 A2A
                 A2B
            A3
        B
            B1
            B2
        C
        D

all of A, A1 A2A are function and with parameters
How design Controller?

Solution 1:
THE PROBLEM IS How can I design A2A function ?

"application/controller/admin.php"
Code:
class Admin extends Controller {

    function __construct() {
         parent::Controller();
    }

    function index() {
        // this is admin
    }

    function A($action = '', $page = 1) {
        // this is A
        // example uri : admin/A/do/2/
        // how can I design A2A function ?
    }

    function B($page = 1, $action = 'testB') {
        // this is B
        // example uri : admin/B/3/testB/
    }
}

Solution 2:

if I create "admin" folder in "application/controller/"
so the struct is
admin/A.php
admin/B.php
admin/C.php
...
and create A class

THE PROBLEM IS how can I set the admin default controller? admin is a dir. And I don't like to modify route config file.

A.php

Code:
class A extends Controller {

    function __construct() {
         parent::Controller();
    }

    function index() {
    }

    function A1($action = '', $page = 1)

    }

#2
[eluser]richthegeek[/eluser]
the admin default controller is Admin::index()

If you want to make a differently named controller run in place of the index, just call the method you want. For example, if you want Admin::A() to run, just add:
Code:
$this->A();
to the index method of the admin controller.

#3
[eluser]vps4[/eluser]
[quote author="php_penguin" date="1213514232"]the admin default controller is Admin::index()

If you want to make a differently named controller run in place of the index, just call the method you want. For example, if you want Admin::A() to run, just add:
Code:
$this->A();
to the index method of the admin controller.[/quote]

no, please see my second part codes
it have no admin.php
admin is a folder

#4
[eluser]vps4[/eluser]
if I create "admin/admin.php"

so my uri must be http://domain.com/admin/admin/A/

I don't like this

I also don't like to modify route config file.

#5
[eluser]xwero[/eluser]
Why not create a controllers/admin.php file as a landing page en put all you other admin controllers in the admin directory. You could do the same for A2. your file structure would look like this
Code:
controllers
  admin.php
  admin
    A.php
    A
      A2.php
    B.php
    C.php

But i wouldn't recommend to create your file structure after your navigation structure. What if you change the navigation? Are you going to change your file structure and/or controller and method names as well?
Create a file structure and name controller/methods in a manner you find best maintainable. If it happens to be like the navigation structure fine, if it doesn't use routing.

#6
[eluser]vps4[/eluser]
[quote author="xwero" date="1213532567"]Why not create a controllers/admin.php file as a landing page en put all you other admin controllers in the admin directory. You could do the same for A2. your file structure would look like this
Code:
controllers
  admin.php
  admin
    A.php
    A
      A2.php
    B.php
    C.php

But i wouldn't recommend to create your file structure after your navigation structure. What if you change the navigation? Are you going to change your file structure and/or controller and method names as well?
Create a file structure and name controller/methods in a manner you find best maintainable. If it happens to be like the navigation structure fine, if it doesn't use routing.[/quote]

thanks a lot, baby

#7
[eluser]Colin Williams[/eluser]
Sometimes the most obvious solution is the best. Also, it might help to get over your routes.php editing anxiety.. just a suggestion Smile

Although, I'd be interested in your reason for avoiding routes.php


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.