Re: [PHP] best way for PHP page

2008-01-02 Thread Casey
On Jan 1, 2008 11:17 PM, Alain Roger [EMAIL PROTECTED] wrote:
 Hi,

 i would like to improve my coding quality when i use PHP code and for that i
 would request your help.
 in my web developer experience, i have to confess that i've never succeeded
 in spliting PHP code from HTML code.

 i mean that all my web pages consist of PHP code mixed with HTML code (for
 rendering pages).
 Some developers tell it's possible to write only PHP code for web page. i
 agree with them but only when those PHP pages do not render web elements
 (write text, display pictures, display formular, ...).

 the purpose of my post is to know if i can really (at 100%) split client
 code (display images, write text,...) from server code (move or copy data to
 DB, create connection objects,...)

 so what do you think about that ?

 --
 Alain
 
 Windows XP SP2
 PostgreSQL 8.2.4 / MS SQL server 2005
 Apache 2.2.4
 PHP 5.2.4
 C# 2005-2008


Yes, you can.

function foo() {
global $data;
//Fetch from database, format, etc. etc.
//Stuff all the data into $data variable
}

function bar() {
global $data;
//Output with HTML
}

$data = array();
foo();
bar();

I'm pretty sure this is what they mean.

-Casey

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way for PHP page

2008-01-02 Thread Sancar Saran
On Wednesday 02 January 2008 09:17:50 Alain Roger wrote:
 Hi,

 i would like to improve my coding quality when i use PHP code and for that
 i would request your help.
 in my web developer experience, i have to confess that i've never succeeded
 in spliting PHP code from HTML code.

 i mean that all my web pages consist of PHP code mixed with HTML code (for
 rendering pages).
 Some developers tell it's possible to write only PHP code for web page. i
 agree with them but only when those PHP pages do not render web elements
 (write text, display pictures, display formular, ...).

 the purpose of my post is to know if i can really (at 100%) split client
 code (display images, write text,...) from server code (move or copy data
 to DB, create connection objects,...)

 so what do you think about that ?


Hello,

I believe TYPO3 has good implementation about splitting code and template.

And to archieve clean php code.

1-) Left html ?php echo $this; ?/html model development
2-) Find good template engine. (no not that smarty, it was too big)
3-) use strict dicipline to move html to outside of the code.

Also if you can use the php based template files you can lift off the template 
overhead.

like.

template.php

$strPage = 
html
head.
title.$strPageTitle./title
/head
body
table
tr
td.$strLeftBlock./td
td.$strRigthBlock./td
/tr
/table
/body
/html;

process.php

$strPageTitle = getPageTitle($_REQUEST['page']);
$strLeftBlock = getPageBlock($_REQUEST['page'],'left');
$strRightBlock = getPageBlock($_REQUEST['page'],'right');

include('template.php');

echo $strPage;

regards

Sancar

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way for PHP page

2008-01-02 Thread Brady Mitchell
i would like to improve my coding quality when i use PHP code and  
for that i

would request your help.
in my web developer experience, i have to confess that i've never  
succeeded

in spliting PHP code from HTML code.


There's a myth that by separating html and php your code is cleaner,  
it's a little more than that. What you should consider doing is  
separating the business logic from the display logic.


The business logic includes things like database calls, data  
calculations, etc.


Display logic is what the page actually looks like. This will likely  
include both HTML and PHP, but the PHP will be limited to echoing out  
variables, as you should have already done all calculations.


One very good way to do this separation is by using the MVC pattern - http://en.wikipedia.org/wiki/Model-view-controller 
. I've found that using the MVC pattern helps me to write cleaner,  
more maintainable code as you always know where the code for a given  
function is located. Need to edit what the page looks like? It's in  
the view. Need to edit your database calls? It's in the model.  
Anything else? It's in the controller.


There are lots of great frameworks out there that use the MVC pattern.  
Personally I use and recommend CodeIgniter (http:// 
www.codeigniter.com) - it's been a great one for me, but there are  
plenty of other well written frameworks out there if CodeIgniter isn't  
a good fit for you.


HTH,

Brady

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way for PHP page

2008-01-02 Thread Nathan Nobbe
On Jan 2, 2008 2:17 AM, Alain Roger [EMAIL PROTECTED] wrote:

 Hi,

 i would like to improve my coding quality when i use PHP code and for that
 i
 would request your help.
 in my web developer experience, i have to confess that i've never
 succeeded
 in spliting PHP code from HTML code.

 i mean that all my web pages consist of PHP code mixed with HTML code (for
 rendering pages).
 Some developers tell it's possible to write only PHP code for web page. i
 agree with them but only when those PHP pages do not render web elements
 (write text, display pictures, display formular, ...).

 the purpose of my post is to know if i can really (at 100%) split client
 code (display images, write text,...) from server code (move or copy data
 to
 DB, create connection objects,...)

 so what do you think about that ?


study up on mvc
http://en.wikipedia.org/wiki/Model-view-controller

then look at some of the popular open source php implementations.
code igniter is very thin and straightforward.
you can quickly see how a php application can be separated into layers.

-nathan


Re: [PHP] best way for PHP page

2008-01-02 Thread Dave Goodchild
If MVC is too heavy for you it may also be worth exploring templating
engines such as Smarty:

http://www.smarty.net/


On Jan 2, 2008 4:10 PM, Nathan Nobbe [EMAIL PROTECTED] wrote:

 On Jan 2, 2008 2:17 AM, Alain Roger [EMAIL PROTECTED] wrote:

  Hi,
 
  i would like to improve my coding quality when i use PHP code and for
 that
  i
  would request your help.
  in my web developer experience, i have to confess that i've never
  succeeded
  in spliting PHP code from HTML code.
 
  i mean that all my web pages consist of PHP code mixed with HTML code
 (for
  rendering pages).
  Some developers tell it's possible to write only PHP code for web page.
 i
  agree with them but only when those PHP pages do not render web elements
  (write text, display pictures, display formular, ...).
 
  the purpose of my post is to know if i can really (at 100%) split client
  code (display images, write text,...) from server code (move or copy
 data
  to
  DB, create connection objects,...)
 
  so what do you think about that ?
 

 study up on mvc
 http://en.wikipedia.org/wiki/Model-view-controller

 then look at some of the popular open source php implementations.
 code igniter is very thin and straightforward.
 you can quickly see how a php application can be separated into layers.

 -nathan



Re: [PHP] best way for PHP page

2008-01-02 Thread tedd

At 8:17 AM +0100 1/2/08, Alain Roger wrote:

the purpose of my post is to know if i can really (at 100%) split client
code (display images, write text,...) from server code (move or copy data to
DB, create connection objects,...)

so what do you think about that ?


Alain:

What do I think about that?

I think there is only one web language and it's called 
php/mysql/html/js/css. For no one language can do it all.


The bigger point is to learn how to separate data, presentation, and 
functionality.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php