| | |
Php And HTML Mixed?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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..
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..
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.
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
I miss my mind the most...."
Mark Twain
•
•
Join Date: Jan 2008
Posts: 141
Reputation:
Solved Threads: 19
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.
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.
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jan 2008
Posts: 141
Reputation:
Solved Threads: 19
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.
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.
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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 ?
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 ?
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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
http://rainbow.cs.unipi.gr/projects/dtps/browser/trunk
If you have the patience!
SOrry for my english
![]() |
Similar Threads
- Web Order - Checkbox Values - sending via php mail (PHP)
- Move Javascript Variable to PHP (JavaScript / DHTML / AJAX)
- File Attachment Small Problem (PHP)
- Session problem (PHP)
- PHPSavant vs. Smarty (PHP)
- Help-Email gone wild...trojan.download (Viruses, Spyware and other Nasties)
- PHP Installation (PHP)
- This ought to be simple - extra spaces (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP+Ajax Help
- Next Thread: ftp_ssl_connect problom
| Thread Tools | Search this Thread |
# 5.2.10 action address apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher destroy display dissertation domain dynamic echo echo$_get[x]changingitintovariable... email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image images include insert ip javascript joomla legislation limit link load login mail masterthesis menu mlm multiple mysql mysqlquery oop open paypal pdf persist php popup problem query radio random record recursion remote script search server sessions sms sockets source space sql syntax system table tutorial update upload url validator variable video web youtube






