Welcome Guest, Not a member yet? Register   Sign In
more than one controller
#1

[eluser]vinod_ci[/eluser]
Hi
I have to create more than one cotrollers.
Because currently, In my controller the code size is beyound 4000 lines.
How i put this number of functions in seperate files and again make call from main controller to this functions.

I have tried one solution for this, the files are:

1. made one base controller
/application/libraries/

class MY_Controller extends Controller {

function MY_Controller() {
parent::Controller();
}
function test_vinod($xyz)
{
echo “hi hello”;
echo $xyz;
}

}
2. for developer1

/application/libraries/

<?php

class devloper1 extends MY_Controller {

function devloper1() {
parent::MY_Controller();

}
function homepage()
{
echo “vinod”;
}
}

same as above i want to create more classes like developer2.....3,4,5
In which developer put his own functions

3. And finally my base controller from which i can call these functions from developers

<?php

class Welcome extends MY_Controller {

function Welcome()
{
parent::MY_Controller();


}

function index()
{
$this->test_vinod(’abc’);

$this->load->library(’devloper1’);
$this->devloper1->homepage();
// likely above statement can i load more libraries (developers)
// and call the functions
}

}

My question: is it way to make compact and clear code?

Thanks
#2

[eluser]Phil Sturgeon[/eluser]
Please can you wrap your examples in
Quote:[code]
tags and elaborate a little, hard to see where your code could be more compact as there is barely anything there.
#3

[eluser]vinod_ci[/eluser]
I have team with 4 developers .
Each developers writes its own functionality and create views and models files.
This views and modals call from controller.
In my application only one controller name as welcome.php

Now Each developer has its own more than 10 functions written in controller.
Now controller size become more and more(Currently 6000 lines.)

How can i reduce this lines?
Can i create a sub-controllers to each developer so each developer put only his own functions in it, which is currently (more than 10 fun) in main controller(welcome.php).
if i do like this then "how can make a call to these functions from main controller".

I want output like this:
1. main controller will be clear, clean , less no. of lines.
2. Each developer can create its own sub controller and theses controllers control by main controller.

Because currently, if any error occurs in main controller, its very difficult to find out from more than 6000 lines.

Thanks for response.
#4

[eluser]xwero[/eluser]
Why do you need to put everything in one controller??? Split up the controllers in sections that are logical for you and your team and assign certain sections to a particular programmer.

I wonder how your routes.php file looks like, it must be a mile long.
#5

[eluser]vinod_ci[/eluser]
Thanks for response

What do u mean by splitting the controllers in sections?
That means can i create more controllers files and assign each one to developers for work.
Can u elaborate some code which contains splitting of controllers in sections.
#6

[eluser]xwero[/eluser]
Lets say your site has following sections : shoes, dresses, hats. Create controllers for those sections with those names and then you see in a glance which section the method belongs to.

So yes you can create more controllers, and please do otherwise the maintenance will be hell.
#7

[eluser]vinod_ci[/eluser]
Thanks for response

As u suggest shoes, dresses, hats these are controllers but i need one main controller which control these controllers.
Because when i make any call to function using url then it always goes to main controller.
So how can i guess this function call for which section?
how can i call the methods of sections shoes, dresses, hats?
or should i make one of these sections as my main controller?
#8

[eluser]xwero[/eluser]
Why are all your urls routed to your main controller? If you have some methods that have to be shared between all your controllers you can still create sections but instead of extending the Controller class they extend your main controller class. Like you showed in your starter topic snippet. devloper1 becomes shoes and you can call it with site.com/shoes

There are libraries that allow you to call controllers, or other classes, in your main controller. search for Modular extensions or matchbox or if you thing they are to much for your needs there is the wick library.




Theme © iAndrew 2016 - Forum software by © MyBB