|
Posted by Henk Verhoeven on 11/18/95 11:44
99m@myway.com wrote:
> Can anyone recommend to me a thin PHP framework? By thin, I mean that I
> don't want a massive amount of code, dependencies, or large learning
> curve.
horde: 17935 KB, depends on PEAR and several php extensions
phpPeanuts: 762 KB, no dependencies, but still quite a learning curve
> However, I'd like to use something that helps me
> abstract the application logic and presentation layer a little better.
> And if there's something that helps me display prettier HTML forms, or
> a seperate package, that's icing on the cake.
>
Try a pattern!
For example if myScript.php contains:
<HTML><HEAD>
<TITLE>My Page</TITLE>
</HEAD>
<BODY>
<?php include('myBody.inc.php') ?>
</BODY>
</HTML>
this will output the content coming from file 'myBody.inc.php' on the
location of <?php include('myBody.inc.php') ?>. Now i guess you can do
this kind of thing too with JSP. But there is an important difference:
the code from the included file is executed inside the function it is
included from. In the example there is no function, but in the following
example there is:
in 'myScript.php':
<?php
require_once('MyPage.class.php');
$page = new MyPage();
$page->service();
?>
in 'MyPage.class.php':
<?php
class MyPage {
function service() {
include('MyPage.skin.php');
}
function printTitle() {
print "My Page";
}
function printBodyPart() {
require_once('MyBodyPart.class.php');
$part = new MyBodyPart();
$part->service();
}
}
in 'MyPage.skin.php':
<HTML><HEAD>
<TITLE><? $this->printTitle() ?></TITLE>
</HEAD>
<BODY>
<?php $this->printBodyPart() ?>
</BODY>
</HTML>
in 'MyBodyPart.class.php':
class MyBodyPart {
function service() {
include('MyBodyPart.skin.php');
}
function printMessage() {
print "Hello World";
}
}
in 'MyBodyPart.skin.php':
<B><?php $this->printMessage() ?></B>
Becuase the skin files are included inside methods, the $this variable
will reference the object whose method includes the skin. This way we get:
- separation of layout and OOP code,
- pages composed from reusable parts
And all this without a framework, without a template engine, all you
need is to follow a simple pattern!
For abstracting application logic:
Give each database table a primary key 'id', make it auto_increment.
Made a class DbObject. Make a subclass of DbObject for each database
table. Make one instance for each record. You can load it from the
database with php's msql_fetch_object() function. Use getter and setter
methods. Wite a delete() method on DbObject that deletes using 'id' column.
Write a save() method for each class. Or better, use "SHOW COLUMNS FROM
$tableName" to write a generic function that writes a value for each
column. If $this->id is not set it must be a new object, do insert. If
it is set, do update.
Write all application logic that is not specific to the user interface
in these DbObject subclasses. The user interface should only access data
through instances of these classes.
Greetings,
Henk Verhoeven,
www.phpPeanuts.org (includes the above patterns and more).
BTW, in investment in knowledge is the best investment you can make.
Knowledge is more flexible then any framework can ever be and lasts
longer too. If a framework helps you te learn how to make better
software that makes the framework only more valuable.
Navigation:
[Reply to this message]
|