W tej części
Cytat
$view-> bazed= $mod-> take('name','password');
pobiera nazwę i hasło użytkownika, ale jak później w części $post->validate() porównać to z formularzami? Powiem tylko, że ten kod co podałem po wysłaniu formularza pojawia się błąd w 30 linii w kontrolerze Niezdefinciowana zmienna: Undefined variable: bazed Cały kod:
Controller:
Kod
<?php
class Control_Controller extends Controller {
public function __construct() {
parent::__construct();
$this->profiler = new Profiler;
}
public function index() {
$view= new View('show');
$view-> title= "Title is displayed";
$view-> begin= "Begin too";
$mod= new Display_Model;
$view-> bazed= $mod-> take('name','password');
$post= new Validation ($_POST);
$post-> add_rules ('name','required','length[2,10]');
$post-> add_rules ('pass','required','length[3,10]');
$post-> add_rules ('pass2','required','matches[pass]');
$post-> add_rules ('text','required');
$post-> pre_filter ('mysql_real_escape_string','name','pass','pass2','text');
if ($_POST) {
if ($post-> validate()) {
if ($_POST['name']== $bazed-> name) {
$mod-> ins ($_POST['name'],$_POST['pass']);
echo 'Done.';
}
}
else {
echo 'Somethings wrong';
}
} // end $_POST
$view-> name= form:: input ('name');
$view-> passw= form:: password ('pass');
$view-> pass2= form:: password ('pass2');
$view-> submit= form:: submit ('submit','Send');
$view-> render (TRUE);
}
} // end class
?>
class Control_Controller extends Controller {
public function __construct() {
parent::__construct();
$this->profiler = new Profiler;
}
public function index() {
$view= new View('show');
$view-> title= "Title is displayed";
$view-> begin= "Begin too";
$mod= new Display_Model;
$view-> bazed= $mod-> take('name','password');
$post= new Validation ($_POST);
$post-> add_rules ('name','required','length[2,10]');
$post-> add_rules ('pass','required','length[3,10]');
$post-> add_rules ('pass2','required','matches[pass]');
$post-> add_rules ('text','required');
$post-> pre_filter ('mysql_real_escape_string','name','pass','pass2','text');
if ($_POST) {
if ($post-> validate()) {
if ($_POST['name']== $bazed-> name) {
$mod-> ins ($_POST['name'],$_POST['pass']);
echo 'Done.';
}
}
else {
echo 'Somethings wrong';
}
} // end $_POST
$view-> name= form:: input ('name');
$view-> passw= form:: password ('pass');
$view-> pass2= form:: password ('pass2');
$view-> submit= form:: submit ('submit','Send');
$view-> render (TRUE);
}
} // end class
?>
Model:
Kod
<?php
class Display_Model extends Model {
public function __construct() {
parent:: __construct();
}
public function take($post, $post1) {
return $this->db -> select ($post, $post1)
-> from ('things')
-> get();
}
public function ins($post, $post1) {
return $this->db-> insert ('things',
array(
'name'=> $post,
'password'=> md5($post1)
));
}
}
?>
class Display_Model extends Model {
public function __construct() {
parent:: __construct();
}
public function take($post, $post1) {
return $this->db -> select ($post, $post1)
-> from ('things')
-> get();
}
public function ins($post, $post1) {
return $this->db-> insert ('things',
array(
'name'=> $post,
'password'=> md5($post1)
));
}
}
?>
View:
Kod
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title><?php echo $title;?></title>
</head>
<body>
<ul>
<li><?php echo $begin; ?></li>
<?php foreach ($bazed as $yeah): ?>
<li><?php echo $yeah-> name . $yeah-> password; ?></li>
<?php endforeach; ?>
</ul>
<form action="" method="post">
<div id="form">
<?php
echo $name;
echo $passw;
echo $pass2;
?>
<textarea name="text" rows="10" cols="20"></textarea>
<?php echo $submit; ?>
</div>
</form>
</body>
</html>
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title><?php echo $title;?></title>
</head>
<body>
<ul>
<li><?php echo $begin; ?></li>
<?php foreach ($bazed as $yeah): ?>
<li><?php echo $yeah-> name . $yeah-> password; ?></li>
<?php endforeach; ?>
</ul>
<form action="" method="post">
<div id="form">
<?php
echo $name;
echo $passw;
echo $pass2;
?>
<textarea name="text" rows="10" cols="20"></textarea>
<?php echo $submit; ?>
</div>
</form>
</body>
</html>