Php And HTML Mixed?

Reply

Join Date: Oct 2008
Posts: 8
Reputation: parhs is an unknown quantity at this point 
Solved Threads: 0
parhs parhs is offline Offline
Newbie Poster

Php And HTML Mixed?

 
0
  #1
Dec 1st, 2008
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..
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: Php And HTML Mixed?

 
0
  #2
Dec 1st, 2008
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.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: Php And HTML Mixed?

 
0
  #3
Dec 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Php And HTML Mixed?

 
0
  #4
Dec 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: parhs is an unknown quantity at this point 
Solved Threads: 0
parhs parhs is offline Offline
Newbie Poster

Re: Php And HTML Mixed?

 
0
  #5
Dec 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: Php And HTML Mixed?

 
0
  #6
Dec 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: parhs is an unknown quantity at this point 
Solved Threads: 0
parhs parhs is offline Offline
Newbie Poster

Re: Php And HTML Mixed?

 
0
  #7
Dec 2nd, 2008
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 ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: parhs is an unknown quantity at this point 
Solved Threads: 0
parhs parhs is offline Offline
Newbie Poster

Re: Php And HTML Mixed?

 
0
  #8
Dec 2nd, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC