標籤:測試 size strong var index.php isp http this www.
最近幾天在測試php的mvc,從網上找到幾個樣本。
先學習這一篇,http://www.cnblogs.com/q1ng/p/4529496.html
標題是 PHP的MVC架構 深入解析,其實是最簡單的,感謝Q1NG的代碼。
有了第一篇的基礎,學習第二篇,http://www.cnblogs.com/foonsun/p/5788564.html
標題是 php簡單實現MVC,和第一篇差不多,內容更進一步了。卻叫簡單實現,這位仁兄挺謙虛。感謝喬曉峰的代碼。
第一篇沒錯,很順利,第二篇有錯誤。
第二篇,視圖View這一節課中,參數錯誤,無法開啟頁面
原始碼無法執行,會提示定義錯誤,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
改成
// 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
注意,$view->display($data);改成$view->display($this->data);
順手記一下,做類的建構函式時,使用舊式寫法比較安全些。
下面這個代碼是另一篇教程中的,無法執行,代碼錯誤,
地址 http://www.cnblogs.com/soundcode/p/6903826.html 感謝左正的代碼。
class test
{ var $b;
function test() { $this->b=5; }
function addab($c) { return $this->b+$c; }
}
$a = new test(); echo $a->addab(4); // 返回 9
改成下面這樣就可以了。
class test
{ var $b;
function __construct() { $this->b=5; }
function addab($c) { return $this->b+$c; }
}
$a = new test(); echo $a->addab(4); // 返回 9
php樣本的錯誤記錄