Welcome Guest, Not a member yet? Register   Sign In
Change string in controller from model
#1

[eluser]Swedie[/eluser]
* okay editing *

Can you from a model, change a property that exists in the parent controller?

For example like this: $this->Controller->property = "something new".

It is probably really simple. It's been a long day...
#2

[eluser]LuckyFella73[/eluser]
* edited *
could have been more friendly ..
#3

[eluser]Swedie[/eluser]
*removed some of the faulness *

The question is pretty simple. Can you change a property of the parent controller from a model? If so, how.
#4

[eluser]LuckyFella73[/eluser]
* edit *
off topic now
#5

[eluser]Swedie[/eluser]
* updated first post *
#6

[eluser]SPeed_FANat1c[/eluser]
LuckyFella73 is right, I also did not understand what did you want, but just ignored, thinking maybe some other guy understand.
#7

[eluser]techgnome[/eluser]
I get it...

The short answer is: No, you cannot.

The longer answer is, if from inside the Model you are trying to update something in the Controller, then you have something fundamentally wrong. the Model should be passing data back to the Controller... but it shouldn't directly be interacting with the controller.

Perhaps the question is then, what is it you're trying to update and why?

-tg
#8

[eluser]Bart Mebane[/eluser]
One of the principles of the MVC architecture is that the Model is independent of the Controller and the View, and doesn't know anything about them. The usual way of handling what you're trying to do would be to have the controller request whatever data it needs from the model in order to update its own properties. In other words, the controller knows why the data is needed, but doesn't know the details of where it comes from. The model knows how to get the data, but doesn't need to know what it's being used for. Is there a way you can rework your model and controller to use that approach?
#9

[eluser]kaejiavo[/eluser]
Hi Swedie,

you just do it the other way round. From your controller you call the model function to change your property
$this->property = $this->model->function();

Of course you can add the controller property as parameter to the function and make some calculations / changes to it:

$this->property = $this->model->function($this->property);

Marco
#10

[eluser]tonanbarbarian[/eluser]
I agree with techgnome and bart.mebane, this is not something that you should be doing because it goes against the principles of MVC

however it is possible to do, you get an instance of the controller and the make the change
Code:
$CI =& get_instance();
$CI->property = “something new”;

but as indicated above you are better off returning the data and having the controller make the change
or if you find you have some complex logic in the model that is not about data then create a library and do it from there instead




Theme © iAndrew 2016 - Forum software by © MyBB