[eluser]Edemilson Lima[/eluser]
CodeIgniter allow us to use sub-folders for our controllers and our views. I started my application using them, but I noticed that it changes the way we organize the application scripts.
For example, without sub-folders, you can have:
Code:
// application/controllers/login.php:
class Login extends Controller {
function Login() {
parent:controller();
}
function index() {
// shows the login form
}
function check($par1,$par2) {
// check user login and password
}
function username($par1,$par2) {
// search for the username, if the user forgot it
}
function password($par1,$par2) {
// send the password to the user
}
}
With the code above, you can access the controller functions with the following URIs:
/login/check/par1/par2
/login/username/par1/par2
/login/password/par1/par2
But, if you use sub-folders, you will have:
Code:
// application/controllers/login/welcome.php:
class Welcome extends Controller {
function Welcome() {
parent:controller();
}
function index() {
// shows the login form
}
}
// application/controllers/login/check.php:
class Check extends Controller {
function Check() {
parent:controller();
}
function index($par1,$par2) {
// check user login and password
}
}
// application/controllers/login/username.php:
class Username extends Controller {
function Username() {
parent:controller();
}
function index($par1,$par2) {
// search the username, if the user forgot it
}
}
// application/controllers/login/password.php:
class Password extends Controller {
function Password() {
parent:controller();
}
function index($par1,$par2) {
// send the password to the user
}
}
As you can see, without sub-folders you put the tasks of your application into the same controller, as methods of it.
With sub-folders, you must separate the code from these methods into different controller files. Well, at least if you want to access them by the same URIs I posted above.
Of course, we can have more functions inside each file. Another option would be put everything into the welcome.php file, but I think this make the sub-folders unnecessary.
My question is: did you people that already finished some works with CI, did you needed to organize the controllers into sub-folders or is it better to put everything into the controller's root directory anyway? Does it depends on the size of the application?
I hope I made myself clear. If you don't understood, I will try explain it better.