Michael9 Posted July 17, 2007 Share Posted July 17, 2007 hey all, I'm wondering what tools and techniques people use to do stuff with PHP. yes yes, I know it depends. but in general, let's say you have a BIG project to complete, how would you do it? there are programmers that all they use is direct PHP, there are some people that use template engine [ie Smarty] and some database abstraction [ie- ADODB ] , there are people that use some MVC framework or something else. so, what are you guys using most of the time? Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/ Share on other sites More sharing options...
metrostars Posted July 17, 2007 Share Posted July 17, 2007 I just code all PHP myself and use mysql as the database? Don't know what smarty or MVC framework or anything is. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300489 Share on other sites More sharing options...
drewbee Posted July 17, 2007 Share Posted July 17, 2007 Objects all the way. Objects make my code incredibly easy to maintain. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300534 Share on other sites More sharing options...
rlindauer Posted July 17, 2007 Share Posted July 17, 2007 I use whatever the project requires. Sometimes it is a framework like Codeigniter, sometimes it is just a collection of classes and functions that I have written. Sometimes I use a templating engine. Usually, I just use php for templating since php is a templating engine. I switch between Dreamweaver, TextMate, and Coda to write code. I primarily use MySQL for data storage. You just have to look at the problem and find your best solution for it. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300548 Share on other sites More sharing options...
per1os Posted July 17, 2007 Share Posted July 17, 2007 Depends on the project man. MySQL if a database is required. For project management see my signature for Eclipse with PHP Plugin, the best project management software I ever used. As far as other posts, stay far away from Dreamweaver. Nothing but trouble. Template engines I use one called ETS (Easy Template System) 1 file, cannot get any simpler. I do also use classes, but that depends on the project. For a simple site with an email form, chances are I would not use classes/OOP. Where as a bigger system such as a blogging system I would use OOP. It all depends man, but Eclipse is by far the best editor I ever used. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300569 Share on other sites More sharing options...
rlindauer Posted July 17, 2007 Share Posted July 17, 2007 Dreamweaver is only trouble if you rely on it to write code for you. Zend studio was pretty nice. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300581 Share on other sites More sharing options...
Liquid Fire Posted July 17, 2007 Share Posted July 17, 2007 Zebd Studio was buggy and slow for me(at version 5.1 or something like that). PHPeD is just as good as send studio with feature and is a solid application, it also cost 60 less right now(they always say sale is goin gto end but it has been sales since Xmas. if you can't afford 239 for and IDE i have heard good thing about Eclipse. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300598 Share on other sites More sharing options...
ballhogjoni Posted July 17, 2007 Share Posted July 17, 2007 I use Dreamweaver to code (makes it very easy to distiguish the code) and then mysql for a database. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300600 Share on other sites More sharing options...
rlindauer Posted July 17, 2007 Share Posted July 17, 2007 Zebd Studio was buggy and slow for me(at version 5.1 or something like that). PHPeD is just as good as send studio with feature and is a solid application, it also cost 60 less right now(they always say sale is goin gto end but it has been sales since Xmas. if you can't afford 239 for and IDE i have heard good thing about Eclipse. Weird, Zend Studio worked great for me, it was eclipse that was buggy and slow Maybe I will give it another try Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300617 Share on other sites More sharing options...
roopurt18 Posted July 17, 2007 Share Posted July 17, 2007 How much thought, care, and design you put into a program is really answered by the question: How much do you care about its maintainability? If it's a large project that you'll be working on for a while or may be coming back to in six months, putting some thought and effort into some sort of design (whether it's object oriented or procedural), will pay off. If this is a quick project that you're setting up for someone else it really doesn't matter if you put a lot of thought or effort into it since they don't know squat about it. I know this sounds like lousy advice but the primary concerns for the client are 1) How long will it take (i.e. cost) 2) Does it function? No matter how well designed or implemented, there is no such thing as a software project that doesn't require maintenance. Therefore, clients and project managers will budget this accordingly. They expect to pay you or someone else at a future point to come in and modify the software. If they ask you to return to maintain it then you've won yourself more money in the pocket. If they ask someone else and your design is terrible, that next person might hate your guts, tell the client how bad you were, and then the client might hate your guts; but that didn't hurt your situation as they didn't ask you to maintain the software anyways. Note that what I said about not needing to design does not imply that you should be careless about validating data or error checking. You should always take the proper precautions when dealing with user input. It's hard to design when you're first starting off. It takes a lot of practical experience to be able to sit down ahead of time and think of everything before you actually face it. A lot of the developers that frequent these forums have their own code libraries that they've built up over time, adding new features as the need arises. The good news is that programming is a self-optimizing art-form. After you perform the same 3 lines of code repeatedly on a single page you will say to yourself, "Maybe I should wrap this in a function." Let's say those particular three lines dealt with data validation. After you've created a bunch of data validation functions that are jumbled all over, the better sense in you should be saying, "I really should gather those into a central location." Design can only be taught by others to a certain extent. Most of what people know about design is what they've experienced first hand. P.S. Don't bother with template engines. As rlindauer pointed out, PHP is itself a temple engine. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300618 Share on other sites More sharing options...
Michael9 Posted July 17, 2007 Author Share Posted July 17, 2007 roopurt18, thanks, very useful reply. about the template engine, why don't use them? I mean, with direct PHP it's all very messy, I think that some good template engine can make the life easier. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300680 Share on other sites More sharing options...
trq Posted July 17, 2007 Share Posted July 17, 2007 about the template engine, why don't use them? The bigger ones can slow execution down quite a bit. I mean, with direct PHP it's all very messy, I think that some good template engine can make the life easier. Its personal opinion, but its quite easy to organize your logic so as there is only very minimal php scattered arround. eg; logic.php <?php // norammaly pulled form a database or some other source. $title = 'my articles'; $articles = array(array('title' => 'this is foo'),array('title' => 'this is bar')); include 'display.php'; ?> display.php <html> <head> <title><?php echo $title ; ?></title> </head> <body> <?php foreach ($articles as $article) { ?> <p><?php echo $article['title']; ?></p> <?php } ?> </body> </html> This sort of syntax isn't really any more difficult to use then some of the crazy syntax the template engines inforce on you. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300689 Share on other sites More sharing options...
trq Posted July 17, 2007 Share Posted July 17, 2007 Even easier using the alternate syntax and short tags. <html> <head> <title><?= $title ; ?></title> </head> <body> <? foreach ($articles as $article): ?> <p><?= $article['title']; ?></p> <? endforeach; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300695 Share on other sites More sharing options...
roopurt18 Posted July 17, 2007 Share Posted July 17, 2007 There's a couple of reasons why I don't like them. The first is they complicate an already complicated process. From initial request to final output, the code will travel and branch through several layers of abstraction before the final output is sent back to the browser. The second reason is they force you to learn a new syntax. You will soon find that template engines have special syntax for repeating portions of code, testing conditionals, setting temp variables, etc. By the time you get through with them you've set up a bunch of extra stuff that PHP already handles for you. I agree with you 100% that direct PHP can be very messy, but it doesn't have to. When I first started programming PHP I kept all of my HTML separate from my PHP. I essentially did the following: small_template.html <!-- a small example html template --> <p>{MSG}</p> small_script.php <?php $html = file_get_contents("small_template.html"); $msg = "Hello, World!"; $html = str_replace("{MSG}", $msg, $html); echo $html; ?> This worked fine for a while. It kept my HTML and PHP separate which made it handy if I needed to view my HTML in a web browser. However, I quickly learned that I rarely looked at the plain .html file in a web browser. Also, I was having to type str_replace() many, many times. And lastly I couldn't do any form of conditional testing or looping within the template itself. If I wanted to repeat a section of a template I'd have to create a new .html file, loop over it many times building a bigger string of HTML, and finally embed that in another HTML template. I designed / developed my first site like that which was fine; it was a site for a gaming guild and nothing professional. When I was hired where I currently work a year ago, I was supposed to take over an existing project. The project I inherited had many files that were extremely long, some well over 500 lines, that were procedural code with very few function calls that constantly jumped back and forth between PHP and HTML. It's programming like this that makes me agree when you say using straight PHP can be messy. Imagine trying to find the matching curly brace on an if statement when its 200 lines down the page and there are almost 100 <?php's in between. An impossible situation. Realizing I didn't want to keep using my original solution and I certainly didn't like the solution the developer before me used, I reached a middle ground. I came up with what I call components. Components, to me, represent a single unit of user interface; i.e. I only turn something into a component when it will be displayed on the screen. employee_table.php <?php /** * Example component that generates an employee table. */ /** * Expects vars: * array $People; Array of arrays, where each internal array has keys: * fname, lname, phone */ if(!isset($People) || !is_array($People) || !count($People)){ // Nothing to do here $txt = "There are no people to display."; echo CreateStandardText($txt, "left"); return; } ?> <table> <tr class="titles"> <td>Last</td><td>First</td><td>Phone</td> </tr> <?php foreach($People as $p){ ?> <tr> <td><?=$p["lname"]?></td> <td><?=$p["fname"]?></td> <td><?=$p["phone"]?></td> </tr> <?php } ?> </table> This component is very simple, it just generates a table. It may be called like so: <?php function showPeople(){ $People = PeopleDAO::GetPeopleFromDatabase(); include("employee_table.php"); } ?> This is overly simplified, but look at the component file again. You will notice that the top portion is entirely PHP and the bottom is mostly HTML with some PHP. This is how all of my components are designed. I do any processing before the HTML portion of the component and I limit myself to only echoing values, testing conditionals, and looping in the HTML portion. Now you might ask why I didn't just put the call to PeopleDAO::GetPeopleFromDatabase() inside the component. This is a matter of preference. Let's say that I had four more functions that also returned people from the database. By assigning $People outside of the component, I can pass the result of any of the functions to the component; therefore I can use the same component to display many sets of data (as long as the data has the same format). There's a little more that goes into it in the stuff I use day to day, but that gives you an idea. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300721 Share on other sites More sharing options...
per1os Posted July 18, 2007 Share Posted July 18, 2007 The only reason for using a template engine, is incase you want users to be able to do their own templates but do not want them access to php commands. That is the only reason I use ETS for my blogging software. I want users to be able to have full control over their blog without having any other control. =) Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-300802 Share on other sites More sharing options...
drewbee Posted July 18, 2007 Share Posted July 18, 2007 The only reason for using a template engine, is incase you want users to be able to do their own templates but do not want them access to php commands. That is the only reason I use ETS for my blogging software. I want users to be able to have full control over their blog without having any other control. =) I would have to disagree with this. I use a template engine on every single one of my sites, and it makes maintaining it 500 times easier. Through the template engine that I use, I can not only change the look / layout of my entire site with one file, but make changes to forms, form validatoin, and db handling from the form in a matter of a few minutes. Adding fields to my form is literally a 3 step process that takes about 5 minutes to do. And this includes the presentation and logic of it. Quote Link to comment https://forums.phpfreaks.com/topic/60405-what-is-your-way-for-doing-stuff-with-php/#findComment-301176 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.