Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Example Web site.
#1

[eluser]TheFuzzy0ne[/eluser]
Hi everyone.

I'm having a serious problem here. I'm trying to design a bespoke Web site for a company which sells candy. I have designed a template, and know exactly what I want to do, but I can't seem to get the structure right, and as a result, coding is becoming very complex. The problem I am having is with the structure. I am trying to come up with a simple way to display pages, which in itself seems like a simple question, but I am finding that my code is a lot more bloated than it needs to be as I am having to define lots of variables within the controller, such as the page title, header variables, footer variables, navigation menu title and contents etc...

I have been thinking about using models, and having a model for each page which will hand back the variables for the template, but the bloat is still there, just not in the controller. Also, with views, I am finding that I have lots of fragments, which is bloating the directory structure. I think my problem here is simply organisation. I think I try to keep things lean in the early stages of a project, which complicates it more for me. But I know there is a way to keep my code lean, without having to complicate things like I am.

I've tried to find an example of a whole Web site, so I can try and figure out how I should structure everything, but the only thing I seem to be able to find is example applications. I have no problem creating applications, it's integrating them together into one site I am struggling with.

I have an admin section too, and the controller is getting bloated, so I need to break it up into other controllers. I'm not sure how to handle a user accessing the controller who is not admin. Should the constructor redirect them away from the pages? Do I need to create a function that's called upon within each controller function? Should the function even redirect the user? I have lots of ideas, and I can never decide which one to go with, so any pointers here would really help me.

Would anyone have any pointers, or know of any URLs where I might be able to download a complete Web site, rather than just a single application? I know it's a really big question, and everyone has their own way of programming, so often there is not only one correct way of doing things, but I know I am going about this project the _wrong_ way, and I need to get myself back on the right track before continuing further.

Thanks in for reading. I'd appreciate any replies.

EDIT: I'd also like to know how I should handle multiple translations of the same document, but with large documents, for example, Privacy Policy, or About Us. I have no problem translating strings, I'm just not sure how I should handle larger amounts of data. Does CI support this natively, or do I need to emlpoy one of my ugly hacks?
#2

[eluser]TheFuzzy0ne[/eluser]
Sorry, this was meant to have been posted in "Code and Application Development". I thought that was the link I'd clicked on, but evidently it wasn't. If someone would be so kind as to shift this post over to there, I'd really appreciate it.

Thanks.
#3

[eluser]Nick Husher[/eluser]
Suggestion: check out Derek Allard's BambooInvoice application written in CodeIgniter. It's not a perfect analogy, but it gives you an idea of one way you can lay out an application in CI.

Also, you might not want to be using CI for what you're doing: it seems like you're writing a lot of boilerplate code when you really need a CMS. You could either adopt some of the nascent CMS projects for CodeIgniter or you could try your hand at more mature solutions like Drupal or ExpressionEngine.
#4

[eluser]Mirage[/eluser]
Hey there -

Sounds like an ambitious project. It's a bit difficult to know where you can optimize without knowing what your variables are which you're setting everywhere.

The first thing you can probably save on is controller methods. For views that don't require pre-processing of input data, I create a 'Page' controller with a _remap method. That controller is reached by a catch all rule that doesn't match any other routes (last one in router.php :

Code:
$routes['(.+)']='page/$1';

You could of course also be more specific with regards to routes that should map to static pages. Using a catchall like the above also will require that you write exclusions for controllers/methods that are not static. The _remap method inspects the URI and load the appropriate view file for segment 1. The other segments can be evaluated in that view to include sub-templates where needed.

For translations, I've extended the core Language library to provide functionality for handling urls that include language identifiers in the first url segment like
Code:
http://site.com/en/controller/method/param
http://site.com/en_US/controller/method/param

A good start of how this can work can be found in the WIKI.

Translations are stored in a database. I maintain a 'language' table structured similarly to CI's language files, but us a db because of easier front-ending in an admin UI. I also have a cms helper that loads 'content-blocks' which are stored in the database for each language.

With regards to structure, I keep my view scripts in directories that match the 'sections' of a site. Keep your includes sensible. I usually include 'head' and then they typical blocks - navigation, header, content, footer - in the main view file. keep in mind that you can load further sub-views which might be dependent on the URL in each view. I used to use just 'include' php statements - but an excellent suggestion how you can do it with the CI view is here.

Then there are various view libraries which you can find in the WIKI, or Colin William's Template Library here.

You are absolutely correct that everyone has their own way of programming and you'll have to do some diligent research and perhaps ongoing refactoring until you found 'your' CI style. For what it's worth - it took me 6 projects to settle on a base approach. But I still don't use that everywhere - because it's not equally useful everywhere.

Admin stuff - if it's really involved, I create an admin folder in the controllers directory and break out the controllers by functionality. Protect your admin section with one of the Auth Libraries promoted here in the forums. I rolled my own based on Zend_Auth and Zend_ACL, but there are plenty alternatives.

I don't know of any 'downloadable' CI 'website' projects. And frankly it's a bit much to ask I'd say. Read, discuss, learn and apply. That's the only thing to really get you there.

Hope this provides you with a start.
-m
#5

[eluser]metaltapimenye[/eluser]
[quote author="Mirage" date="1221548127"].. with a _remap method. ..[/quote]
xsczme..would you mind to teach me (with case) how to applied _remap feature. if its ok send me a PM.thx
#6

[eluser]TheFuzzy0ne[/eluser]
Fantastic advice, folks. Thanks a lot for your feedback. bambooinvoice is the "example web site" I've been looking for. Smile
#7

[eluser]TheFuzzy0ne[/eluser]
[quote author="metaltapimenye" date="1221561308"]
xsczme..would you mind to teach me (with case) how to applied _remap feature. if its ok send me a PM.thx[/quote]

There is a good example in the User Guide here.
#8

[eluser]alaminx[/eluser]
i don't understander what u say




Theme © iAndrew 2016 - Forum software by © MyBB