Welcome Guest, Not a member yet? Register   Sign In
Getting data from other controller
#1

[eluser]Whis[/eluser]
Hello, I'm a new user of CI and I have some questions Smile.

Is it possible to retrieve data from other controllers?

I tried to pass variables with CI sessions in other controllers, but it doesn't work (same issue for the repopulating method). The variables are just destroyed (I have not the same problem when I call the same controller). Does CI unset all the Global variables when a new Controller is called? How can I use multiple controllers and CI sessions? Is it possible to create a form in a controller and validate it in another one? (and repopulating it)

Thanks Whis. Smile
#2

[eluser]jalalski[/eluser]
Store the data in a session? Or use flashdata?
As a controller is instantiated from a URL (e.g. index.php/mycont/func1/para) there will only ever be one controller active, so it's either sessions, POST vars or db/file storage.
#3

[eluser]Whis[/eluser]
I understand there is only one controller active.

But when I’m trying to store variables in a controller thanks to the CI sessions (not flash data) or repopulating a form from another controller, the variables are just erased...

For example, if I have a form located in "first_controller" and I try to validate it in "second_controller", I can't repopulate this same form (in "first_controller").


Do not understand why Confused. I think that CI unset those arrays when initialized a new controller.
#4

[eluser]Colin Williams[/eluser]
Show some code.
#5

[eluser]Developer13[/eluser]
What about Wick?
#6

[eluser]jalalski[/eluser]
[quote author="Whis" date="1232941195"]I understand there is only one controller active.
But when I’m trying to store variables in a controller thanks to the CI sessions (not flash data) or repopulating a form from another controller, the variables are just erased...
For example, if I have a form located in "first_controller" and I try to validate it in "second_controller", I can't repopulate this same form (in "first_controller").
Do not understand why Confused. I think that CI unset those arrays when initialized a new controller.[/quote]

Not normally. As Colin said, I think we need to see a bit of code to understand what you are doing.
#7

[eluser]Whis[/eluser]
I solved the problem! Smile

I thought that CI didn't need "session_start()" but yes. Indeed, it seems to work perfectly with this line and not without it.

For the forms, I don't use the same controllers to display the form and validate it, so I can't retrieve the variables that CI generates to repopulate in my first controller (unless I store it in flashdata for example).

Thanks, Whis.
#8

[eluser]Colin Williams[/eluser]
Sounds like an odd way to design it.




Theme © iAndrew 2016 - Forum software by © MyBB