PHP - writing content and code
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: PHP - writing content and code

  1. #1
    Join Date
    Aug 2002
    Location
    Dubai
    Posts
    1,183

    PHP - writing content and code

    Hi,

    I am an ex C++ , VB, CSharp coder in a state of retreat from windows programming. I would like to move on web programming as that seems to be the in thing these days. I am very much interested in learning PHP to a professional level.

    I have learned most of the language fundamentals using small example scripts created using a text editor (Textpad).

    Now I would like to move on to more advanced things. What I would like to know is how does one create elaborate pages in PHP ?

    It seems a bit overwhelming to hand code all that HTML. Normally if the page is a bit elaborate I would use an HTML editor like front page or dreamweaver. So how does one mix the scripting and the UI creation in PHP ? Are there IDEs which help you do that ? What do most professional PHP coders do ?

    Regards

    Sahir
    Last edited by Sahir; July 13th, 2009 at 07:28 AM.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,865

    Re: PHP - writing content and code

    Sounds like you're talking about PHP templating to write HTML pages. Personally, that's quite easy and doesn't require any advanced coding. Here's a simple example. You can use header and footers, but I like to keep it all in one document. There are plenty of examples which vary. Just search around for them.

    template.php
    PHP Code:
    <?php
    if (!isset($rel)) {$rel './';}
    if (!isset(
    $header)) {
      
    $header true;
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <title><?php echo $pageTitle?></title>
        <style type="text/css">
          @import url(<?php echo $rel?>css/main.css);
        </style>
      </head>
    <body>

    <?php } else { ?>

    </body>
    </html>
    <?php ?>
    Now, you would reference it as follows.

    index.php
    PHP Code:
    <?php
      $rel 
    './'// this is your relative path
      
    $pageTitle 'Home Page';
      include 
    'template.php';
    ?>

    HTML content here

    <?php include 'template.php'?>
    When it comes to PHP IDEs...Take a look at this thread.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Aug 2002
    Location
    Dubai
    Posts
    1,183

    Re: PHP - writing content and code

    Quote Originally Posted by PeejAvery View Post
    Sounds like you're talking about PHP templating to write HTML pages. Personally, that's quite easy and doesn't require any advanced coding. Here's a simple example. You can use header and footers, but I like to keep it all in one document. There are plenty of examples which vary.
    Many thanks for the reply. My question was how does one integrate the "headers and footers" into the PHP code ? Suppose the page contains just 10 to 15 lines of php code and a large amount of HTML with lots of nested tables, images , css etc. Do people hand code all that or do they use some HTML editor like Frontpage/Expression Web to create the page and copy paste the relevant HTML into the PHP code between the ?> and <? tags ? So do you end up using two editors ? The PHP IDE to write/edit the PHP code and the HTML editor to create the HTML part ?

    Basically, I am wodering if there are PHP IDEs that work roughly like how Visual Studio works for creating ASP.NET pages.

    I have an old version of dreamweaver (8.0) which I purchased some three or four years ago but never installed. I have heard that Dreamweaver can be used for PHP code. How good is Dreamweaver as a PHP IDE ?

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,865

    Re: PHP - writing content and code

    Quote Originally Posted by Sahir View Post
    Many thanks for the reply. My question was how does one integrate the "headers and footers" into the PHP code ? Suppose the page contains just 10 to 15 lines of php code and a large amount of HTML with lots of nested tables, images , css etc. Do people hand code all that or do they use some HTML editor like Frontpage/Expression Web to create the page and copy paste the relevant HTML into the PHP code between the ?> and <? tags ? So do you end up using two editors ? The PHP IDE to write/edit the PHP code and the HTML editor to create the HTML part ?
    You would do headers and footers almost the same way I do one file. Instead of including the same one at both the top and bottom, you would include the header at the top, and the footer at the bottom. You wouldn't need the extra $header variable, but still need the relative path one. There are plenty of examples out there!

    PHP is coded by hand...no ways around that. It isn't a visual language at all. It is a server-side language that outputs to a client for all its visuals.

    You can design HTML using many different IDE's. That is very simple. Personally, I code everything by hand because that is the most precise and best way to fit web standards.

    Quote Originally Posted by Sahir View Post
    Basically, I am wodering if there are PHP IDEs that work roughly like how Visual Studio works for creating ASP.NET pages.
    Nope.

    Quote Originally Posted by Sahir View Post
    I have an old version of dreamweaver (8.0) which I purchased some three or four years ago but never installed. I have heard that Dreamweaver can be used for PHP code. How good is Dreamweaver as a PHP IDE ?
    Dreamweaver is for people who do not know HTML or CSS. It is a crutch, not a useful tool. Personally, I hate it! Note that it does not do PHP templating.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2009
    Location
    Belgium (Country in Europe)
    Posts
    44

    Re: PHP - writing content and code

    Quote Originally Posted by Sahir View Post
    I have an old version of dreamweaver (8.0) which I purchased some three or four years ago but never installed. I have heard that Dreamweaver can be used for PHP code. How good is Dreamweaver as a PHP IDE ?
    I always use WAMP server to view my pages (with php).
    http://www.wampserver.com/en/download.php

    It also features a MySQL database. To use it:
    1)Install it. Then putt your required files (your css,html, php, js, ... files) in this directory: c:\wamp\www\

    2)Run WAMP server as admin.
    3)Left click the icon in your toolbar. And select "Localhost".

    It will then open your index.html or index.php or ... file in your browser. And you can browse your webpage on a localhost.

    Hope this was of any help.

    Greetz,
    Dave

  6. #6
    Join Date
    Aug 2002
    Location
    Dubai
    Posts
    1,183

    Re: PHP - writing content and code

    Quote Originally Posted by PeejAvery View Post
    Personally, I code everything by hand because that is the most precise and best way to fit web standards.
    Ah! I think that answers my question. Thanks.

    Just one more doubt. What method do you use to control layout ? Do you use nested tables or a lot of DIV tags with absolute positioning ?

  7. #7
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,865

    Re: PHP - writing content and code

    Neither. I do use <div> tags with CSS, but almost never do I touch absolute positioning. Doing that will give you no control over how the clients with different resolutions see your pages.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    730

    Smile Re: PHP - writing content and code

    Sahir,
    welcome to PHP world. I hope you enjoy and stay.

    I'll write some brief notes of what and how I do professional webdev with PHP:

    1. When you get the idea behind web programming and PHP, search about MVC in PHP. MVC is the industry defacto standard for building web applications. ASP.net uses MVC.
    2. Use a solid PHP framework. Increases production, stability and has a community you can run for answers.
    3. Develop with magic_quotes OFF, register_globals OFF and error_reporting = E_ALL. If a framework doens't work with those settings, throw it in the garbage.
    4. Again on MVC, if you do it the right way you can concentrate on the Model and Controller parts and optionally let a designer do the layout. MVC separates data/business logic (model), app logic (controller) and the layout (view).
    5. Don't do JavaScript by hand. Use a framework. I highly recommend jQuery.
    6. When I create a new project (site) create 2 folders for it:
      1. /sitename/docs <- holds all documents, designer raw files (PNG, PSD, JPG, FLV), researches, contract, SQL schema and backup.
      2. /sitename/www <- holds the actual website files.
    7. Use Version Control Software even if you are a one-man-army. Recomend modern VCS like git, mercurial and bazaar (i use this).

    Ok let me stop here, just the basics. I might have missed some important points. Can't think now.

    Have fun.
    All consequences are eternal in some way.

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    105

    Re: PHP - writing content and code

    Dont bother with wysiwyg editors for html, most of them just generate a lot of overhead code.
    For the php editor I would recommend Eclipse with the php and html plugin.
    There you will have coloured code to check if your syntax is ok.

  10. #10
    Join Date
    Aug 2002
    Location
    Dubai
    Posts
    1,183

    Re: PHP - writing content and code

    Quote Originally Posted by bubu View Post
    [*]Use a solid PHP framework. Increases production, stability and has a community you can run for answers.
    Hi Bubu,

    Many thanks. I did not know about PHP frameworks. That sounds promising. What is a good framework I can use ?

  11. #11
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    730

    Lightbulb Re: PHP - writing content and code

    Some frameworks go so far that they actually hide PHP from you. So make sure you mastered PHP before you try a framework.

    I'd advice you to find a simple framework you like.

    Avoid these for now (not necessarily for ever):

    • CakePHP: I like this one, but don't use it. It's magic! Actually it's too magic.
    • Zend Framework: This is currently a piece-o-crap. They rushed its development. The result is some pseudo-modular crap you must join yourself to make something out of it. And the documentation is a comedy. If you like modularity go with Pear.
    • PRADO: great but complex.
    • Symfony: High learning curve.
    • Any framework that tries to mimic Ruby on Rails. They pretend to be too magical. The only good framework from this family is CakePHP.
    • Any frameworks that attempts to copy Java framework. Why try to make a tiger (PHP) act like a whale (Java)?
    • Any framework with "Enterprise" on its introduction text. They are often too complex.
    • Frameworks heavily based on code generation. They force you to do things in one way, their way. Only take this path when you're a Master Yoda of PHP.

    I'd recommend for you:

    • Akelos
    • CodeIgniter (despite not liking it very much for my very own dumb reasons)
    • LightVC: Very simple framework to learn MVC with.
    • Your own mini MVC framework. Take this path if you have the NIH syndrome.

    And please guys, don't start a flamewar. This is my personal-self-mine opinion on frameworks, considering his position and I'm giving it because he asked.
    Last edited by bubu; September 4th, 2009 at 01:12 AM.
    All consequences are eternal in some way.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center