Welcome Guest, Not a member yet? Register   Sign In
how can I "jump" (request) from controller to controller???
#1

[eluser]jorgeakanieves[/eluser]
hi all!

i´m developing an codeigniter changed application and I´d like to know how could i call from a controller to other controller.. An example will be more explicative...

admin.php ...
Code:
class CIAdmin extends Controller{
           __construct{
               parent::Controller();

               // check auth
               require_once(BASEPATH."/application/controllers/users/users.php");
               $users = new Users();
               $users->check();

               // this is not VALID !!!!!!!!!!!!!!!!!
               //(I call Controller again because users.php has the same structure)
           }      
}
...


It´s a bit annoying, isn´t it?

I´m trying to create a modular application...
#2

[eluser]johnwbaxter[/eluser]
I think you should go and have another look at the user guide, this is explained there and there is demo code too thankfully!

However you don't need to use require, you could move your users.php into a library then you can simply do this:

$this->load->libary(users)

The great thing about CI is the use of libraries IMHO, i'm constantly trying to move everything into a library to minimise the the amount of code in my controllers.
#3

[eluser]Pygon[/eluser]
Controllers should not be interacting with controllers anyway (other than to redirect a request in the event of failure or similar).

Seems to me that you're using a controller instead of a model for user validation.
#4

[eluser]johnwbaxter[/eluser]
Indeed, libraries is where you want to be going.
#5

[eluser]jorgeakanieves[/eluser]
yes, as I see...All the code has to go on libraries to be accesible by all the controllers but Mmmmmmmm...I think it´s not suitable to a modular, scalable and big application... If i delete a module with its applications, models and views it´d have working fine...
#6

[eluser]johnwbaxter[/eluser]
If you want to get modular do a search on the forums for "matchbox".

Matchbox is a contribution by someone that allows you to do what you are trying to do i think.

Good Luck with it though, i'm sure you can accomplish whatever you need with CI, that's the beauty of it.
#7

[eluser]jorgeakanieves[/eluser]
Thanks for all! I´ll see the matchbox.
#8

[eluser]Seppo[/eluser]
Other way is extending the controller class, and defining common private methods there.
#9

[eluser]webthink[/eluser]
So what's not modular and scalable about using libraries?
#10

[eluser]wiredesignz[/eluser]
Using libraries for any type of interaction between MVC components is bad practice, a library generally takes some input processes it and provides output.




Theme © iAndrew 2016 - Forum software by © MyBB