Welcome Guest, Not a member yet? Register   Sign In
Best practices with modules, CI, and seperating idea.
#1

[eluser]Unknown[/eluser]
Hey everybody.

I've been scripting/programming for a while now (mostly HTML, C#, and VB.NET), though I know a decent amount of PHP. I recently picked up CodeIgniter and although I'm not usually big into application development I've been working on a new idea for a project. I started a couple of days ago, but I have a couple of little quirks that I wanted some suggestions for from some more seasoned programmers. It's mostly just best practice stuff.

- The first thing I was wondering was what the best practice was for modulating your application. Right now I have a basic template system in place, but (for example) my site is going to have a user badge situated at the top right of every page that displays a profile image, the user name and some basic user links based on your login status. I was thinking of creating yet another folder within my views called "modules" and just coding it separately, then including it within my header file, but... would I benefit that much more from that rather than just coding it into my header? Or even, is it worse practice to modulate my project that much, rather than just make another view for my badge?

It's a small logic problem for me with my folder/file set-up and like I said, I was wondering for some input from some of you, since you probably have much more experience in this. Basically, what's best practice when you're breaking up your views modularly?

- Also, my conception right now tells me that 'models' pull data, 'views' format that data, and 'controllers' display those views in an appropriate way for people to interact with them. That's basic MVC, but as I said, I'm not a big app. programmer, so I was wondering, is it bad practice to load up your view with most of your html, including your page formatting?

Because right now I'm basically putting all I need into my view (including data manipulation and page formatting), then simply using the controller to display that and subsequently link between views.



I know this is more of a MVC question and not a CI question, so I apologize, I really do. I just can't wrap my head around some of these bigger principles and I'd rather get them down now rather then later on in my project, so I don't have to re-do evvvvvvvvvvvverything.
#2

[eluser]BrianL[/eluser]
What you need are not programming best practices but web best practices. First, use modern design by using <div> tags with id attribute to wrap every single view (except possibly the main view for each page). Then when loading views, load them into a string in whatever order you choose. You can create your header, footer, menu bar, and content in whatever order you please each with individual view files. Now since each view file will be wrapped in a div tag with a id, you can place it exactly how you want with CSS. Basically you will have ultimate separation of presentation and logic layer, completely unlike ASP.NET. I suggest creating a custom naming convention for views based on the controller name, for example call your views [controller name]_[id number] and [controller name]_main for the main view. You do not need to worry about exactly how you break up your views, because that will all be handled and positioned exactly with CSS. How "fine grain" you want your views will depend entirely on your needs. The lowest level is generally a view a foreach loop, and the highest level are views for your headers, footers and body. Again I suggest you invent your own naming convention.

I suggest this. Views should be broken up to avoid any looping and as little PHP in the view as possible; only enough PHP to access variables. With PHP out of the way you can give the views to a web designer with no knowledge of PHP and only basic knowledge of HTML if necessary, and they can alter CSS and javascript at will without touching your code.




Theme © iAndrew 2016 - Forum software by © MyBB