Welcome Guest, Not a member yet? Register   Sign In
Newbie: where to put my code?
#1

[eluser]Unknown[/eluser]
I'm sure it has been answered a lot of times but I've been searching and I haven't found the answer. I'm sorry in advance.

I'll try to explain my problem (my English level is poor and my MVC knowledge near zero).

I have a class A that contains dozens of class B objects and these objects can contain other objects of Class C. Every class have his own persistence, attributes, lots of functions. Normally using OO pure it isn't a problem as I can explode every class as I want, but trying to apply Codeigniter MVC I don't know how I must do it.

The user can do actions using class A or class B.

So I understand I must have:
Class A controller - Class A model
Class B controller - Class B Model
- Class C Model

Maybe I misunderstand something but as I've read is not a good MVC practice to call a controller from other controller or to call a model from other models... So what can I do to do this in the best way?

Only way I find is this one:
A.php:
include_once ('B.php')<-- B Controller
class A extends CI_Controller{
var $list_of_B=array();
function save(){
call to A_model.save()
call to B->save() <-B Controller
}
}

B.php:
include_once ('C.php') <-- Controller of C
class B extends CI_Controller{
var $list_of_C=array();
function save(){
call to B_model.save()
call to C->save()
}
}

Is it the right way to do things? How must I do it using CodeIgniter Best practices?







#2

[eluser]Aken[/eluser]
It is not good practice to call one controller from another.

It is perfectly acceptable to call one model from another.




Theme © iAndrew 2016 - Forum software by © MyBB