Welcome Guest, Not a member yet? Register   Sign In
Codeigniter File structure
#1

[eluser]bhefny[/eluser]
I'm new to codeigniter but I'm very familiar with PHP.
But i'm really struggling to build a good file structure using codeigniter.
My problem is that I really want o rely on the framework and standards since I can get the task done regardless.

now I'm building a new website from scratch. and I want to have "about us" & "contact us" pages. How can I make them (not How but more what is the standard in codeigniter):
1) Should I have one controller and it calls multiple view files (one view file for "about us") and another for "contact us"? [meaning the actual HTML details of the page like phone number and stuff will be in the view file]
2) should each have two file, the "about" should have it's controller file and it's view file and
"contact us" the same?
3) Should I have two controllers and in this controller I should prepare all my code (even if I used obstart() ) and both controllers call this one template view file? [meaning the actual HTML data like the phone number and divs will be in the control file and passed through a variable to the view for display]

all three cases can be done and it's not about the technicality, it's following the standard that will eventually help on the long run

Thank you.
#2

[eluser]jdfwarrior[/eluser]
Ideally, the only time you would group two pages in the same controller would be if they shared a similar function. For instance, creating a 'user' controller that had functions for 'login', 'register', etc.

I'm assuming that you do understand that your code would need to be in the application directory. I would create a controller for each and just have the basic index function in each controller, that loaded the view for that page.
#3

[eluser]BrianDHall[/eluser]
I would use the default controller you have setup for your project. Then I'd create an about_us() function (page) and a contact_us() function, each loading their own respective View.

Unless its being stored in the database, you would just hard-code the data into the View as 'content'. If multiple pages have use for this information I would create a config file for your site so you can change it all in one place, then anytime you want the company phone number you might do something like $data['phone'] = $this->config->data('phone'), etc - and pass that to the views.

If you are doing lots of configurable information you would then go over and start handling that in a database, but for simple apps there is no need.

If you are only using information in a very few places it isn't so bad to just type it in the view and be done with it - but if you are going to use it more than that it's best to set it is a variable.
#4

[eluser]Colin Williams[/eluser]
I don't even know why you would use CI on this project.
#5

[eluser]bhefny[/eluser]
[quote author="Colin Williams" date="1255401151"]I don't even know why you would use CI on this project.[/quote]

I haven't given any details of how big/small is this project.
Regardless of the size, one would still need a about and contact page.
#6

[eluser]bhefny[/eluser]
I can totally understand making a view for each page.
But as a check, do any of you guys get to use ob_start() in their controllers?




Theme © iAndrew 2016 - Forum software by © MyBB