943,737 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1710
  • PHP RSS
Dec 1st, 2008
0

Php And HTML Mixed?

Expand Post »
Hello. I have downloaded some ready projects and i saw that they seperate html from php. They are echoing everything through a class.For example they make a class for <html> tag for <body> etc.
This is driving me insane.Whats wrong with just having some classes and then mix html and php to display the data ?I think its lot simpler. Otherwise i get lost ..If they need 100 includes just to display a simple page.I read many books and everywhere i saw mixed mode.
So whats right? How should i design my sites? Represanting each html tag with a class how the heck then a designer could design something? Isnt simpler just have a template ?
Please help..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008
Dec 1st, 2008
0

Re: Php And HTML Mixed?

It is up to you. If you start building a large website with a lot of repeating code like headers, navigation menus, etc, you will realize how helpful the includes are.
Later on, you will realize that a database-driven site, with a lot of if/else statements becomes really hard to maintain, because you have a lot of code to verify and navigate within, so you will be looking in the direction of objects, where you call an object instance and it displays as needed. Changes become much more easier and the whole site becomes easily maintainable.

Books are good to give you the basics, they show how things may be made, but books not always show the best practices. It is good to read the books, as they would eventually explain a lot of the ideas implemented in the ready-made projects. A ready-made project is hard to understand, because actually you are going into reverse engineering, rather than development. It is good to understand the ideas behind ready-made projects and reduce their capabilities to the limits of your requirements.
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Dec 1st, 2008
0

Re: Php And HTML Mixed?

Personally, I create a main template, and then divide repeating or interchangeable elements up into smaller templates.

I then combine the templates using a template class I've written, substituting templates in for placeholders, etc, before outputting the complete page.

I find it works really well. Essentially its following the MVC principle.

R.
Reputation Points: 101
Solved Threads: 74
Posting Pro in Training
blocblue is offline Offline
427 posts
since Jan 2008
Dec 1st, 2008
0

Re: Php And HTML Mixed?

Where I work, we have designers that don't know php and seperating html and php will make the integration of the php code and the actually design a lot faster. This is very important when the website is handled by more than one person. If its just you, than its personal preference.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Dec 2nd, 2008
0

Re: Php And HTML Mixed?

Yes i understand but how could a designer do something if they have a class for html tag and for each tag like <body> <head> etc..
IS this necessary ?
Also do you know any good books for oop in php ? I want to see some examples what they do..
Also is it a good practise to create a database object and then pass it through a function? Example
Users::registerUser(blah,database); where database is the active connection at the database.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008
Dec 2nd, 2008
0

Re: Php And HTML Mixed?

I think having a class for each and every HTML element is serious overkill... although without seeing a specific example, I may be wrong. I find using one PHP class to generate HTML pages works very well.

With regard to passing a database connection, in my work, I have always used a database class, and each one of my scripts creates a new instance of the class, which will then retrieve an active DB connection. If your class has an object handle on a database class instance, you can reference it from within the class using $this->

Finally, tutorial wise, I've not used them. I had the advantage of learning on the job. Best option may be to Google for OOP PHP. There must be hundreds of tutorials on the net.

R.
Reputation Points: 101
Solved Threads: 74
Posting Pro in Training
blocblue is offline Offline
427 posts
since Jan 2008
Dec 2nd, 2008
0

Re: Php And HTML Mixed?

Thank you for your answer. I amnt sure if i understood well what you do about the database.
Suppose i have a page that uses database to get some news and to get some info about what the user has bought from the database again.
So News class and User class how should reference to the database?
creating a database like that
database = new Database();
database->connect();
News->showBlabla(database) ;
User->Getblabla(database);
Or News and Usser should create its own database object so 2 connections per request ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008
Dec 2nd, 2008
0

Re: Php And HTML Mixed?

Also if you want to see about the project i am talking that uses a class for each html tag see that
http://rainbow.cs.unipi.gr/projects/dtps/browser/trunk
If you have the patience!
SOrry for my english
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP+Ajax Help
Next Thread in PHP Forum Timeline: ftp_ssl_connect problom





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC