Data transfer between controller functions |
[eluser]TheFuzzy0ne[/eluser]
It's not to do with safety, but more to do with the MVC pattern. The whole point of MVC is that you keep your models and views separated.
[eluser]Mareshal[/eluser]
I tried again the following code MAIN controller Code: function index(){ VIEW index.php Code: <?php I tried to call following URLs: 1st - http://localhost/testme -> returns "my query" and "Undefined variable: sub" 2nd - http://localhost/testme/index.php/main/subscribe -> "Undefined variable: query" and "subscription done" 3rd - http://localhost/testme/index.php/main/renderpage -> returns "my query" and "subscription done" ONLY WITH THIS CODE which is not correct in my opinion Code: function __construct() { Also I tried with or without $this in some cases, and no success. How can I get 3rd result with 1st code ?
[eluser]TheFuzzy0ne[/eluser]
Why have a separate method to render the page, when you can just do $this->load->view('main/index', $data)? If you absolutely must have that method, you should consider prefixing it with an underscore so it can't be access via the URI.
[eluser]Mareshal[/eluser]
I tried n0xie's suggestion. I only try to use the data from another function in same controller, and that was only a simple example.
[eluser]garymardell[/eluser]
Your getting the undefined variables as with your example you set $this->data["sub"] in one controller function and the query in another. Now when you go to say localhost/main/subscribe it calls the subscribe function. This sets your data["sub"] but query is still empty. Now if you were to define in your contruct both of the variables to be inially set to "" or something then you wouldn't get the error of missing the other param.
[eluser]Mareshal[/eluser]
yes, I know why I am getting undefined variable, but how to use function in function in same controller? How to load a 2nd view in 1st view, while a controller is sending data to 2nd view? I don't know if you understood. VIEW 1st.php $this->load->view('2nd.php'); but in the same time, or previously a controller is sending data to 2nd view. I am trying to load the entire data in 1st view only. Like I would have a controller sending data to header, but header is loaded inside index.php.
[eluser]TheFuzzy0ne[/eluser]
I feel that you need to have a look around a bit more for inspiration. Please see my [url="http://ellislab.com/forums/viewthread/107773/"]CodeIgniter Resources thread[/url]. It might help you get a clearer picture of how to do things.
[eluser]Mareshal[/eluser]
thanks, but I've already clicked that link from your sig yesterday. I read most of the content form there, but now there are 2 cases, I don't see the solution to my problem. Am I blind or am I blind? :|
[eluser]garymardell[/eluser]
Okay, i don't think i quite understand what your trying to achieve. You trying to share the same data over two pages. As in you want the same data after redirecting the user? So you send the user to local/x and then have some data and then if they go to local/y the controller has access to the data from before. Or is it you just want to call the other controller method from another controller method.
[eluser]Mareshal[/eluser]
User is in /local . after subscribe user is sent to /local/subscribe/ . I want here same data like /local + some other data . And also inside a controller I am trying to call a function from another(controller1/function1 calls controller1/function2), or call in controller1/function1 -> controller2/function2. |
Welcome Guest, Not a member yet? Register Sign In |