General PHP applications

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • odwrotnie

    #1

    General PHP applications

    I want to know what is the ordinary style in creating PHP applications.
    Should it be one main index.php which will be processing requests from
    many htmls like in JSP technology?
    Or what?
    Thanks for any help and links.

    And by the way please recomend me a free tool to write and debug PHP
    applications (does not matter linux or windows).
    I know only VS.Php for Visual Studio and this is what I am looking for -
    syntax colors and running the application by one click.

    Thanks!

    --
    Best regards,
    Odwrotnie.
  • geeker87@gmail.com

    #2
    Re: General PHP applications

    > I want to know what is the ordinary style in creating PHP applications.[color=blue]
    > Should it be one main index.php which will be processing requests from
    > many htmls like in JSP technology?[/color]

    Depends completly on the application. If it were a simple blog/homepage
    I'd be tempted to just have one index page and a set of libraries to
    include(). If it were a large-scale, multiuser site along the lines of
    myspace or soemthing, I'd go for a modular approach that gives me
    access to often-used functions throughout, but does not include
    unneccesary code - e.g. calling 'modules' from the index page
    (/index.php?mod=s howUsers).

    Its hard to explain the different approches you can take, but you
    really need to look at the size of the application to begin with.
    [color=blue]
    > And by the way please recomend me a free tool to write and debug PHP
    > applications (does not matter linux or windows).[/color]

    Use any text editor with syntax hilighting to write.
    Testing can be done with a personal webserver, or install something
    like PHPTriad on your machine (Apache, PHP, MySQL all in one package -
    for windows). Theres another out there beggining with an X which has
    perl and python too, but the name escapes me.

    There are full blown PHP IDEs out there, but personally, I wouldn't
    recommend any of them unless you need to collaborate your code with
    other developers, and the only good ones seem to have a hefty price
    tag.

    Just my 2 cents anyway,

    -- Matt

    Comment

    • bobzimuta

      #3
      Re: General PHP applications

      Check out Advanced PHP Programming by George Schlossnagle.

      Personally I like to use an object oriented approach to keep pages
      cleaner. Also, jedit is a good IDE. It provides PHP syntax
      highlighting, code folding and has a large repository of user created
      plugins. I like the FTP plugin for connecting to FTP and SFTP servers,
      an (X)HTML plugin for auto-complete and tag matching, color wheel and
      buffer tabs to display your open files in tabs.

      Comment

      • Ian Collins

        #4
        Re: General PHP applications

        odwrotnie wrote:[color=blue]
        > I want to know what is the ordinary style in creating PHP applications.
        > Should it be one main index.php which will be processing requests from
        > many htmls like in JSP technology?
        > Or what?
        > Thanks for any help and links.
        >
        > And by the way please recomend me a free tool to write and debug PHP
        > applications (does not matter linux or windows).
        > I know only VS.Php for Visual Studio and this is what I am looking for
        > - syntax colors and running the application by one click.
        >[/color]
        (x)emacs has decent PHP support, I'm not sure if it's available for windows.

        --
        Ian Collins.

        Comment

        • Ian Collins

          #5
          Re: General PHP applications

          geeker87@gmail. com wrote:[color=blue]
          >
          > Use any text editor with syntax hilighting to write.
          > Testing can be done with a personal webserver, or install something
          > like PHPTriad on your machine (Apache, PHP, MySQL all in one package -
          > for windows). Theres another out there beggining with an X which has
          > perl and python too, but the name escapes me.
          >[/color]
          Don't forget that PHP scripts can be run form the command line, so you
          don't require a webserver for testing.

          --
          Ian Collins.

          Comment

          • David Haynes

            #6
            Re: General PHP applications

            odwrotnie wrote:[color=blue]
            > I want to know what is the ordinary style in creating PHP applications.
            > Should it be one main index.php which will be processing requests from
            > many htmls like in JSP technology?
            > Or what?
            > Thanks for any help and links.
            >
            > And by the way please recomend me a free tool to write and debug PHP
            > applications (does not matter linux or windows).
            > I know only VS.Php for Visual Studio and this is what I am looking for -
            > syntax colors and running the application by one click.
            >
            > Thanks!
            >
            > --Best regards,
            > Odwrotnie.[/color]

            Editor:
            A reasonable freebie for editing in either environment is Eclipse
            http://eclipse.org with the php plugin


            Architecture:
            It really depends on the demands that will be placed on the system.
            Small applications can be routed through one central controller, more
            complex systems may want to spread the load.

            Personally, I like to have a 1:1 relationship between the code that
            paints the screens (views) and the code that does the business logic
            (controllers) and uses objects to talk to the database (model).

            So, for example, if I have a subject 'foo', I will have a foo.php which
            paints the screen and a foo.ctrl.php which has all the business logic.
            This allows me to code things like foo.cell.php for cell phone displays,
            etc. without changing the business logic code or the database access
            code.

            The rule is foo.php is only called by foo.ctrl.php (via a header()
            redirect) and foo.php will only call foo.ctrl.php (via POST or GET).

            -david-

            Comment

            • scylla101

              #7
              Re: General PHP applications

              I'm using php Coder, available form www.phpide.de

              IT gives proper colours for all php coding. IT also contains a built in
              browser, that can be linked to php and apache or IIS, to make it run.

              IT is windows based.


              odwrotnie wrote:[color=blue]
              > I want to know what is the ordinary style in creating PHP applications.
              > Should it be one main index.php which will be processing requests from
              > many htmls like in JSP technology?
              > Or what?
              > Thanks for any help and links.
              >
              > And by the way please recomend me a free tool to write and debug PHP
              > applications (does not matter linux or windows).
              > I know only VS.Php for Visual Studio and this is what I am looking for -
              > syntax colors and running the application by one click.
              >
              > Thanks!
              >
              > --
              > Best regards,
              > Odwrotnie.[/color]

              Comment

              • odwrotnie

                #8
                Re: General PHP applications

                THANKS!!! YOU HAVE HELPED ME A LOT!

                --
                Best regards,
                Odwrotnie.

                Comment

                • odwrotnie

                  #9
                  Re: General PHP applications

                  On Wed, 22 Mar 2006 23:02:36 +0100, David Haynes
                  <david.haynes2@ sympatico.ca> wrote:
                  [color=blue]
                  > The rule is foo.php is only called by foo.ctrl.php (via a header()
                  > redirect) and foo.php will only call foo.ctrl.php (via POST or GET).[/color]

                  Can You give me examples about "via a header()" and "redirect" and POST
                  and GET. I dont really understand what do You mean (I am new to php)...

                  --
                  Best regards,
                  Odwrotnie.

                  Comment

                  • David Haynes

                    #10
                    Re: General PHP applications

                    odwrotnie wrote:[color=blue]
                    > On Wed, 22 Mar 2006 23:02:36 +0100, David Haynes
                    > <david.haynes2@ sympatico.ca> wrote:
                    >[color=green]
                    >> The rule is foo.php is only called by foo.ctrl.php (via a header()
                    >> redirect) and foo.php will only call foo.ctrl.php (via POST or GET).[/color]
                    >
                    > Can You give me examples about "via a header()" and "redirect" and POST
                    > and GET. I dont really understand what do You mean (I am new to php)...
                    >
                    > --Best regards,
                    > Odwrotnie.[/color]
                    Sure.

                    POST and GET refer to the way data may be passed from an HTML <form> to
                    a program - in this case a php program. So, when you create a form, you
                    have something like:

                    <form action="foo.ctr l.php" method="POST">
                    <input type="text" name="something ">
                    <input type="submit">
                    </form>

                    Clicking on the OK button (of the submit) will cause the data in the
                    'text' variable to be sent to the program foo.ctrl.php.

                    The foo.ctrl.php program can access the 'something' data as
                    $_POST['something'].

                    If you set method="GET" or use a url like
                    http://foo.ctrl.php?so mething="hey there", then the program can access
                    the 'something' data as $_GET['something'].

                    Let's say that foo.ctrl.php wants to display the value of 'something' in
                    a web page. My way would be to have foo.ctrl.php redirect the http
                    session to the display page using a header() call.

                    For example:

                    <?php
                    header("Locatio n: show_text.php?s omething=$_POST['something']");
                    ?>

                    The page show_text.php can get the text data using the $_GET['something'].
                    For example:

                    <html>
                    ....
                    <body>
                    The text you entered is <?php echo $_GET['something'];?><br/>
                    </body>
                    </html>

                    Now, sending a lot of data to a form via the URL string can get very
                    messy. PHP provides another method - sessions - to pass data quietly.

                    Using sessions, php.ctrl.php would become:

                    <?php
                    session_start() ;
                    $_SESSION['something'] = $_POST['something'];
                    session_write_c lose();
                    header("Locatio n: show_text.php") ;
                    ?>

                    and show_text.php would become:
                    <?php
                    start_session() ;
                    ?>
                    <html>
                    ....
                    <body>
                    The text you entered is <?php echo $_SESSION['something'];?><br/>
                    </body>
                    </html>

                    The location command has its own issues. Someone posted a nice routine
                    (I'm sorry but I can't recall who it was) to enhance the location
                    command. My version of this is:

                    /**
                    * Module: redirect.inc
                    *
                    * Manages a redirection when there may be a session active.
                    * Also correctly re-addresses URLs that are not absolute.
                    *
                    * @param string $url
                    */
                    function redirect($url) {
                    if( substr($url, 0, 4) != 'http' ) {
                    if( isset($_SERVER['HTTP_HOST']) ) {
                    $url = 'http://'.$_SERVER['HTTP_HOST'].$url;
                    } else {
                    $url = 'http://localhost'.$url ;
                    }
                    }
                    session_write_c lose();
                    header("locatio n: $url");
                    exit;
                    }

                    This function makes all url addresses absolute and ensures that the
                    session is committed prior to the header() redirect.
                    (Thanks again to the original poster)

                    This should get you started.

                    -david-

                    Comment

                    Working...