orionlogic Posted December 16, 2008 Share Posted December 16, 2008 Sorry for my noobish question but i want to talk this with a good programmer. I am not a programmer but i wrote a web application.In this application there are users, user friends, posting articles etc. things like that. Because i don't dive into class theory much, even though i understand what it is, i see creating functions is a faster way to accomplish my task. For example when i want to get a users friends, i directly write a function for this; Basically querying DB & echo the outcome in HTML format directly from inside the function. Nearly every dynamically working part of the application follows this approach. After writing 600 lines of functions, it becomes so boring.But it works, it is fast and its easy for me to understand. Major drawback that i face is, i can't use most of the functions inside the other functions( because it echos HTML) so i wrote nearly identical functions to use inside for another one. A nightmare noobish approach I want to ask what will i going to face later? How can i refine my "only functions" design approach ? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted December 16, 2008 Share Posted December 16, 2008 first, i would start using classes to help organize things. a 'user' or 'person' class is the most common use of classes. second, i RARELY have functions echo anything. they always return the value, and i echo it with the calling script. for example, i would have a 'user' class, with methods like getUsername(), getName(), getEmail(), etc. which return the appropriate values. i would also have a getFriends() method, which would return an array of user objects...one for each friend. then, have the calling script use echos/loops/etc to print the needed HTML. if you are looking to condense and organize your HTML, i would look into Smarty. it's a PHP templating system. you can define a template for displaying a list of users. then have a template for a page of friends that calls that other template. it helps keep a 'standard' across the entire site and makes themes easy to create. ....hope that helps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.