In recent days in testing PHP MVC, find several examples from the web.
Learn this article first, http://www.cnblogs.com/q1ng/p/4529496.html
The title is the PHP MVC framework In-depth parsing , in fact, is the simplest, thanks to q1ng code.
With the foundation of the first article, learn the second article, http://www.cnblogs.com/foonsun/p/5788564.html
The title is PHP simple implementation of MVC, and the first one almost, the content went further. But is called simple realization, this man is very modest. Thanks for the Choshe code.
The first one was right, it went well, and the second article was wrong.
In the second section, the Views view in this lesson, the parameter is wrong, cannot open the page
The source code cannot be executed, prompting for a definition error, notice:undefined variable:
controller/democontroller.php
Class Democontroller
{
Private $data = ' Hello furzoom! ';
Public Function Index ()
{
echo ' Hello World ';
Require (' view/index.php ');
$view = new Index ();
$view->display ($data);
}
}//End of the class Democontroller
End of File democontroller.php
Change into
controller/democontroller.php
Class Democontroller
{
Private $data = ' Hello furzoom! ';
Public Function Index ()
{
echo ' Hello World ';
Require (' view/index.php ');
$view = new Index ();
$view->display ($this->data);
}
}//End of the class Democontroller
End of File democontroller.php
Note that $view->display ($data); $view->display ($this->data);
Remember, it's safer to use old-fashioned notation when doing class constructors.
The following code is in another tutorial, unable to execute, code error,
Address http://www.cnblogs.com/soundcode/p/6903826.html thanks to left 's code.
Class Test
{var $b;
function test () {$this->b=5;}
function Addab ($c) {return $this->b+ $c;}
}
$a = new test (); Echo $a->addab (4); Returns 9
Change it to the following.
Class Test
{var $b;
function __construct () {$this->b=5;}
function Addab ($c) {return $this->b+ $c;}
}
$a = new test (); Echo $a->addab (4); Returns 9
Error logging for PHP samples