SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Ballarat, Vic. Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Code in HTML vs. HTML in PHP Code

    I've been programming in HTML and PHP since the early 90's. I started with vi and notepad and then tried various HTML editors and IDE's. Over the years I have changed software several times but the one that has stuck has been Dreamweaver. I've written all manner of in-house accounting, CMS and even a fairly well known membership/affiliate script and I've had some really good mileage from DW ... but I yearn for a better development environment. I do most of my work by downloading remote files, making changes and uploading. I have no debugger (I messed around with PHPEd but it never felt 'right').

    The main reason I have stuck with Dreamweaver (even with it's infuriating FTP semi-functionality) has been because I like the fact that I can design HTML user interfaces and then basically 'embed' the visual PHP elements using syntax like <?=$myvariable;?> in table cells etc.

    I seem to be in the minority though and I don't know why, so I'm fishing for some clues and maybe even a few tips that will bring me in line with the majority of coders .

    I see a lot of code where most, if not all, of the user interface (ie. HTML code) is echo'd from PHP strings .. hence the subject. I call this 'HTML in PHP Code' as opposed to the way I do it which is, as I've said, by placing small snippets of PHP in the HTML code (at least for the UI part). When you look, in dreamweaver, at a page that is written with all the HTML echo'd you see a blank page in HTML view.

    So this brings me to the crux of the issue I'm having. How do you create web applications efficiently when writing purely in PHP? Do you always develop on your local machine with a web server, debugger and a web browser open on the page you are working on so you can refresh it any time you alter a table or other page element.

    I have, for years now, thought my way was the best way. In recent times though I've longed for a really good development environment with debugging etc and that's why it got me to wondering whether I was fooling myself into believing that I was doing it more efficiently than others when it's really just a case of an old (44) dog not wanting to learn some new tricks.

    I'm really interested to know how others develop and how efficient you find it to be. Software is not really relevant as I'm more interested in knowing whether it is more time consuming when you don't have the UI html code right in front of you. I feel that I'm limiting myself a bit as I sometimes have cause to work, for instance , on sites that use smarty templates. I can work with it and I think it's a great system, but it's still a bit foreign to the way I normally work.

  2. #2
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I work with Dreamweaver too because of the wysiwyg editor.
    And I've never tried any other IDE because I like the debugging in Dreamweaver... echo /exit();

    While debugging might be a blessing in complex apps, sometimes it pushes for more lazy thinking - debug, fix, code.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Ballarat, Vic. Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by _Steve_ View Post
    I work with Dreamweaver too because of the wysiwyg editor.
    And I've never tried any other IDE because I like the debugging in Dreamweaver... echo /exit();

    While debugging might be a blessing in complex apps, sometimes it pushes for more lazy thinking - debug, fix, code.
    Yep...my debugging is much the same ... and my javascript debugger is alert() .

    In recent months I've been developing some applications where it would be really nice just to step through the code. I've also done a lot of C/C++ programming and a reasonable debugger was one of life's essentials. When I started programming with PHP-FI it was basically a form processor and there were no debuggers around back then which is one of the reasons why I'm wondering now, in 2007, whether I'm penalising myself and being inefficient just becaause I've been doing everything in much the same way for about 15 years or so.

    Maybe I'm just going a bit potty ... or having some sort of mid life crisis ...

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you are occasionally getting deja vu, because you seem to be doing similar things over and again - which you don't complain of implicitly - but if its true and you have a nagging feeling that "there must be a better way", then perhaps "optimising code reuse" is a goal you could set yourself.

    Likewise, identifying the various "layers" of your web applications can help you structure your thinking and planning.

    IMO this has little to do with your text ed/gui ed and more to do with the strategies you pursue to become efficient. I am proof you're never too old to learn (52) and have been abusing html since '94 and PHP since '99.

  5. #5
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A lot of larger applications are using templates. In the case of the Smarty system, the templates you edit are HTML but they are compiled into mixed PHP and HTML pages. When working with a system like that, there rarely is a need to do HTML strings or drop in and out of PHP mode.

    Zend Studio and PHPEd are the most popular PHP IDE's. They have full debugging features. They are expensive, but if you are looking for a serious PHP tool, those are the best out there.

    I still use Dreamweaver for templates and HTML pages.

    There is a big push with PHP to go to OOP designs where presentation is separated from logic. It's much easier to maintain each if they are separated in some way, even if it's on the same page. If you aren't going to use templates than I would recommend that you at least try doing all your processing at the top of the page or in an include at the top and then echo results into the HTML below. This at least allows you to work on each on an individual basis.

  6. #6
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I use dreamweaver only because it has (reusable) snippets, just double click and you have your favorite functoins in any app. and also because one of my clents gave it to me because they could not understand it. Didn't like it at first but now am sold. never use dw for ftp, winscp or filezilla works. DW has php debugging?? it does syntax hiliting i know but all I know for debugging is $_printr.

    early 90's, you probably already know this but

    oop is one thing (I need to learn the basics before jumping head first into oop) and not sure how far along you are but the more you use (included) functions and classes the more you will find that everything can be variables and echoed out as in a foreach loop and regex.

    one page can now be a contact form or rss feed or automatic image gallery or a downloadable xcel spredsheet, all depending on a form sumission or a link that gets clicked.

    Basically use php to output a small amount of html and have the database varibles supply the rest.

    I hope this helped, if not ask more.

    loren

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Ballarat, Vic. Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all your comments. Some really useful points made ... particularly about re-usable code and OOP.

    Re-usable code is one of those things that I often say to myself .. I should be building my own 'snippets' library and libraries of my own functions all the time. Heck, if I'd done that for the past 10 or 15 years it would be such a huge time saver.

    Last weekend I decided to set up my development environment and went with what I had some time ago. Still using Dreamweaver for HTML layouts and templates and phpEd for debugging (with it's local web server). I've looked at quite a few editors over the years and tried a few in recent months and I think Dreamweaver/phpEd is a good combo. They both understand unix line terminators (how annoying is it to have an editor putting blank lines in your source code?) and are both very solid applications.

    So .. my 'ideal' dev environment consists of Dreamweaver, phpEd and MySQL installed locally as well.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •