Welcome Guest, Not a member yet? Register   Sign In
scheme for website with codeigniter
#1

[eluser]pieter dekker[/eluser]
Hi!

I just began with CI. I'm creating a portal, in my case there are about 30 webpages within the portal.
Do I need to create a controller for every webpage?

Is there maybe a full demo example from a website created in CI?
#2

[eluser]xwero[/eluser]
A simple way of looking at controllers is if they are sections of your website and the methods are the pages of the section.

controller animals has apes, lions and snakes, controller plants has trees, bushes, flowers
#3

[eluser]gtech[/eluser]
Hello,

The answer is No, you do not need a controller for every page, each function within the controller will serve a valid URL (so each function in the controller can serve a webpage).

Also you can pass parameters to these functions (by adding to the url), which could serve different content to your web-browser depending on the values you pass in. This is because a controller function can load 1 or many views (the bit that displays the HTML), based on the logic you provide. Also values can be read out of a database by calling a model in your controller, which you can also use to alter the html in the view by passing data to it (a view can contain php logic).

I would describe a controller as a class that you can group webpages together.

Maybee you should read through the documentation and follow the examples it wont take to long, and its silly me repeating the documentation:

[url="http://ellislab.com/codeigniter/user-guide/general/controllers.html"]controllers (click here)[/url]
[url="http://ellislab.com/codeigniter/user-guide/general/views.html"]views (click here)[/url]
[url="http://ellislab.com/codeigniter/user-guide/general/models.html"]models (click here)[/url]

if you read all of these you should get a clear understanding of how you can build webpages, and the different ways you can achieve what you want.
#4

[eluser]mistress_shiira[/eluser]
if i have this major functions that need to be implemented:
add
edit
delete
save

is it ok if i have different controllers handle every functionality or am i not optimizing CI here? Smile
#5

[eluser]xwero[/eluser]
If they process similar data it's best to group them in the same controller. It's not really a question about optimizing but about how you design your application.

If you are going to abstract these methods you are going to have a lot of redirects and without good commenting you will lose oversight.
#6

[eluser]gtech[/eluser]
I agree with xwero, I tend to design my database, then have a model for each table, and then I tend to group the controllers by what data base tables they manipulate so for example (createuser, deleteuser, viewuser) would belong in the same users.php controller.

Sometimes the function may need to manipulate more than one table, but then I have to use a bit of common sense to decide which controller/model the function belongs. For example if I have a function that adds a user to customer, then I have to make a decision whether to put the function in the customers controller or the users controller, there is no real right or wrong in this case as long as your consistent throughout the application.

my application is quite big though (25 database tables), so I have to maintain some kind of structure or my code will become unreadable. For a site with a few pages, it becomes less critical.
#7

[eluser]mistress_shiira[/eluser]
thanks for all the reply guys! Smile




Theme © iAndrew 2016 - Forum software by © MyBB