Application Details
A phone book in which we can add, edit, search for, and delete entities.
Database
One table:
(id, first_name, last_name, number, created_at)
MVC stands for Model View Controller
- Model:
- View:
- Data Presentation
- Read-only Access to Model
- Controller:
- Application Logic: Handling Workflow
What's wrong with this code?
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$ip = $_GET['ip'];
$dbh = mysql_connect($hostname, $username, $password) ;
$selected = mysql_select_db("mysql",$dbh) ;
$result = mysql_query("SELECT * FROM user WHERE `ip`=$ip;");
echo "<table><tr> <td>User</td> <td>host</td> <td>ip</td> </tr>";
while ($row = mysql_fetch_array($result,MYSQL_ASSOC
)) {
echo "<td>".$row['user'].'</td><td>'.$row['host'].'</td><td>'.$row['ip'].'</td></tr>';;
} echo "</table>";
mysql_close($dbh);
?> Problems
-
database:
- use a different database server! (e.g. XML file)
- use multiple database servers for different tables.
- Cache the result
- output
- generate a different output (e.g. for cellphones)
- hire a graphist to work on UI. He's unfamiliar with coding.
- security:
- filter inappropriate inputs(e.g. SQL injectors)
- Scalability
Result
function db_connect
(){
$username = "root";
$password = "";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) ;
$selected = mysql_select_db("mysql",$dbh) ;
}
function getUsersByIp
($ip){
return mysql_query("SELECT * FROM user WHERE `ip`=$ip;");
}
function closeDB
(){
mysql_close($dbh);
}
function getPresentation
($result){
echo "<table><tr> <td>User</td> <td>host</td> <td>ip</td> </tr>";
while ($row = mysql_fetch_array($result,MYSQL_ASSOC
)) {
echo "<=<td>".$row['user'].'</td><td>'.$row['host'].'</td><td>'.$row['ip'].'</td></tr>';;
} echo "</table>";
}
$ip = $_GET['ip'];
$result = getUsersByIp($ip);
getPresentation($result)
closeDB();
- Model:
- View:
- Data Presentation
- Read-only Access to Model
- Controller:
- Application Logic: Handling Workflow
Question
How to implement this?
In a table of fruits, show apples in red. Symfony in some words
- MVC
- Relational Object Model (ROM)
- Forms handling
- Security
- Scalability
MVC in Symfony

Topics
- Introducing Symfony
- Exploring Symfony's Code
- Running Symfony
- The Basics Of Page Creation
- Configuring Symfony
- Inside The Controller Layer
- Inside The View Layer
- Inside The Model Layer
- Links And The Routing System
- Forms
- Ajax Integration
- Caching
- I18n And L10n
- Admin Generator
- Unit And Functional Testing
- Application Management Tools
- Extending Symfony
- Performance
- Mastering Symfony's Configuration Files
Learn Symfony
symfony generate:project test
symfony generate:app frontend
symfony generate:module frontend test
symfony propel:build-schema
symfony propel:build-model
symfony propel:build-forms
symfony propel:build-filters
symfony propel:generate-admin frontend Phones --module=phones
symfony plugin:publish-assets
Installation
pear channel-discover pear.symfony-project.com
> pear install symfony/symfony
downloading symfony-1.2.0.tgz ...
Starting to download symfony-1.2.0.tgz (1,283,270 bytes)
.................................................................
.................................................................
.............done: 1,283,270 bytes
install ok: channel://pear.symfony-project.com/symfony-1.2.0
> symfony
-V
symfony version 1
.2
.0
(/path
/to
/the
/pear
/symfony
/lib
/dir)
Admin Generator
symfony propel:generate-crud frontend phc Phones
or
symfony propel:generate-admin frontend phc Phones