I can submit the appliaction structure . I am not using not Zend nor Symphony, or something else
If a user types a message and enteres “Send” I can just simply via JavaScript add that message to the rest of the messages but I have doubts that in terms of MVC it is correct because you change the view (because we are adding a new message) but from the other hand we dont do require_once(another_view)(which will contain updated messages). Since I am not strong in MVC . I will tell you that I understood MVC like way of coding where you will have controllers which will decide with what view to do require_once .
So all my doubts are around that JavaScript that it is a view but we change the view without working any controller .
I hope I explained something
BTW I thought this . What if we just dont immediatly add the "sent " message to other messages ,and what if via ajax we will go to “index.php” where we will detect that message has come from the "Send burtton " and then will do require_once ?
Here is what all I have for now .
My application is incomlete but i’ll list for you what I have .
All the the application is inside “lc” folder
and inside it I have 4 folders and the index.php file which looks like this:
index.php
<?php session_start();
require_once "includes/config.php";
require_once "models/Db.php";
if(isset($_SESSION["username"])){
require_once "views/logged.php"; // view
}else{
if(isset($_POST["username"]) && !empty($_POST["username"])){
$_SESSION["username"] = $_POST["username"];
$username = $_POST["username"];
require_once "views/logged_first.php"; // view
}else{
require_once "views/register.php"; // view
}
}
?>
Inside the first “includes” folder I have for now only “config.php”
config.php
<?php
defined("DB_HOST") ? null : define("DB_HOST","localhost");
defined("DB_USER") ? null : define("DB_USER","root");
defined("DB_PASS") ? null : define("DB_PASS","sky");
defined("DB_NAME") ? null : define("DB_NAME","livechat");
?>
The Models folder includes “Db.php” file
Db.php
<?php
class Db{
public $connection;
public $selected_db;
private static $instance;
private function __construct(){
$this->connection = mysql_connect(DB_HOST,DB_USER,DB_PASS);
if(!$this->connection){
die("Couldnt connect to the database ".mysql_error());
}else{
echo "Successfuly connected to the database .<br/>";
}
$this->selected_db = mysql_select_db(DB_NAME,$this->connection);
if(!$this->selected_db){
die("Couldnt select a database ".mysql_error());
}else{
echo DB_NAME." database successfuly is chosen. <br/>";
}
$query = "SELECT * FROM chat WHERE id<14";
$result = mysql_query($query);
while($row =mysql_fetch_array($result)){
echo $row["id"]. " ".$row["user"]." ".$row["time"]." ".$row["message"]."<br/>";
}
}// End "__construct()" method
public static function getSingleton(){
if(!self::$instance instanceof self){
self::$instance = new self();
}
return self::$instance;
} // END "getSingleton()" method
} // End "Db" class
?>
The controller folder is not ready since for now the controller’s function does the index.php file . After I will separate it and put it in the controller
In the “views” folder I have
3 files for now
register.php
<html>
<head>
</head>
<body>
<form action="index.php" method="POST">
Nickname:  <input type="text" name="username">
<input type="submit" value="Enter" name="submit" >
</form>
</body>
</html>
logged.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Basic</title>
</head>
<body>
<?php
echo "<h3>Welcome back ". $_SESSION["username"]. "</h3> "."<br/>";
$db = Db::getSingleton();
?>
</body>
</html>
and this which is not that much important
logged_first.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Basic</title>
<script type="text/javascript"></script>
</head>
<body>
<?php
echo "<h3>Logged for the first time: ----Welcome----</h3><br/><br/>";
echo "Logged in as : ".$_SESSION["username"];
$db = Db::getSingleton();
?>
<form >
<input type="text" name="message">
<input type="button" value="Send" onclick="addMessage()" id="send">
</form>
</body>
</html>
Please just dont pay attention on that my __construct outputs messages I’ll orginize it in the way it is supposed to .
[/quote]