Welcome Guest, Not a member yet? Register   Sign In
Controllers and Views
#1

[eluser]CodeIgniterNoob[/eluser]
It might sound like a dumb question, but do I have to create a new controller and a view for that controller for every page of a site that I might build? I want to follow one template, and one controller for different views. Does it make sense? Can anyone help?
#2

[eluser]Jay Turley[/eluser]
If I understand your meaning, then no, you don't.

One controller can load many views. Each function you define in a controller corresponds to a URL. And each function can load different views.

So for instance the function login() in a User() controller might load a login_form.php view, while the User/signup() function might load create_account_form.php.

Just for example.
#3

[eluser]CodeIgniterNoob[/eluser]
So I can have many controllers in one file loading to one view file?
#4

[eluser]Christopher Blankenship[/eluser]
Short answer, Yes.

I utilize the following way myself.

/application
| views
| template.php

/templates
| login.php
| home.php

I pass a variable in my data to the template page which then includes the appropriate /templates file for the page and to this i can add additional modules. Everyone has a way they like, this way makes sense to me.
#5

[eluser]Colin Williams[/eluser]
I wrote and released a Template library that helps me facilitate using a master template (or multiple master templates) across an application. It is by no means the only way to achieve this, but you can follow the link in my signature and decide for yourself.
#6

[eluser]rt30000[/eluser]
I don't think it's a dumb question. I'm just a little ahead of you, here's my story: I just started using CI myself and the MVC approach is very new to me. I started building my first site with CI this past week and after playing with it for a while I am starting to understand how this whole MVC thing works. I am using multiple controllers that all end up loading a single master_template.php view and passing it which additional views/subcontent to display. The data gets pulled by the controller using the models, but for testing you can just as easily hand code the data in the controller. It all makes more sense the more you use it.

It was definately daunting trying to learn both the MVC approach and how CI works at the same time, but I still can't believe where I've gotten in less than a week of working with it. I
#7

[eluser]CodeIgniterNoob[/eluser]
Yea Im also using a master template which I store in the application/libraries folder and I call on it like this from my controller $this->template->load('mainTemplate', 'home', $data); All my controllers will be in one file, querying different database tables and will all load into one view file. I hope Im doing this right, feels right in my opinion. And Im way ahead of time! I started using CI this week.
#8

[eluser]John_Betong[/eluser]
[quote author="NuclearArt" date="1224108323"]It might sound like a dumb question, but do I have to create a new controller and a view for that controller for every page of a site that I might build? I want to follow one template, and one controller for different views. Does it make sense? Can anyone help?[/quote]
 
 
I have experimented with numerous techniques of Controller and View files. What I now prefer is simplicity (KISS) so that it is easy for me to read the code, debug and modify. Take a look at this post:
 
[email=http://ellislab.com/forums/viewthread/90724/]http://ellislab.com/forums/viewthread/90724/[/email]
 
Maybe not the best way for others but it works for me.
 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB