Connecting Tech Pros Worldwide Help | Site Map

General PHP applications

odwrotnie
Guest
 
Posts: n/a
#1: Mar 22 '06
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
Guest
 
Posts: n/a
#2: Mar 22 '06

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=showUsers).

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

bobzimuta
Guest
 
Posts: n/a
#3: Mar 22 '06

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.

Ian Collins
Guest
 
Posts: n/a
#4: Mar 22 '06

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.
Ian Collins
Guest
 
Posts: n/a
#5: Mar 22 '06

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.
David Haynes
Guest
 
Posts: n/a
#6: Mar 22 '06

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
http://www.phpeclipse.de/tiki-view_articles.php

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-

scylla101
Guest
 
Posts: n/a
#7: Mar 23 '06

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]

odwrotnie
Guest
 
Posts: n/a
#8: Mar 23 '06

re: General PHP applications


THANKS!!! YOU HAVE HELPED ME A LOT!

--
Best regards,
Odwrotnie.
odwrotnie
Guest
 
Posts: n/a
#9: Mar 23 '06

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.
David Haynes
Guest
 
Posts: n/a
#10: Mar 23 '06

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.ctrl.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?something="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("Location: show_text.php?something=$_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_close();
header("Location: 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_close();
header("location: $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-

Closed Thread