Welcome Guest, Not a member yet? Register   Sign In
Newbie question: how to load different functions output to a single view file?
#1

[eluser]Unknown[/eluser]
Hi!

I'm just starting with CI and php developing in general, so far I've read the user guide and some tutorials, and I think I have a grasp of how it all works together, however...

... Im building my first application with CI, and I am not sure how I should do the following:

My app is an "activity screen", that is, its just a simple screen that will show the activities for the day, along with some promotional flash videos, a weather widget, a clock widget, etc. From what I've understood, you define the different functions for your app in the controller file, and each function has to be called separately, for ex, the update function, insert function, and of course the main index() function. My question is, let's say I have a function for uploading/updating videos, another function for updating the activities of the day, since they are 2 different functions , one for managing the videos, and the other for managing the activities, how would I make just 1 general view file, which would display both the activities, videos, etc? Would I need to chain the output of the different functions, and then send that to the main index() function, which in turn would send all the data to the view file?

I dont know if I explained myself correctly... Please tell me so if I didnt.

Any ideas/suggestions? :question:

Thanks a lot!

Camilo
#2

[eluser]Sarfaraz Soomro[/eluser]
The functions you define in your controller map directly to a URL (unless you precede them with an underscore).

You can actually have both the functions for fetching/setting data in the model and have your controller interact with the model. In the controller you can process/pass-on the output from model to your view file.
#3

[eluser]Teks[/eluser]
@Camilo: short answer: yes, you call all your functions from the index() function in the controller, and then send the compiled data to the view.

Longer answer: as Sarfaraz described above, if your application is using databases and/or models, then some of the data fetching and gathering functions would probably be at the model level. In your controller's index() function, you would then load the model(s) - and call any necessary model functions - and then pass the resulting model data on to the view.
#4

[eluser]Unknown[/eluser]
Hi!

Thanks for the help! I got confused because so far the tutorials I've found they all have different functions calling different views, for example, the insertcomment() function then loads the comments_view file, the loadmovies()function calls the movie_view file, and so on. But in my project, there is only _one_ view file, the main screen, which will have to be populated by data processed and sent from different functions, for example, the videos, the activities, etc.

But your replys helped me clarify things up, thanks! I'll try and if I get stuck I'll just come back here and ask! =)

Regards,
Camilo




Theme © iAndrew 2016 - Forum software by © MyBB