準(zhǔn)備工作:
我用的開(kāi)發(fā)環(huán)境是windows下的apache+mysql+php
編輯器不知道該用哪個(gè)好,暫時(shí)用dreamweaver吧
我自己的http://localhost/對(duì)應(yīng)的根目錄是E:/website/localhost/

yii的下載地址是https://github.com/yiisoft/yii2/releases/download/2.0.0/yii-basic-app-2.0.0.tgz
備用下載地址:http://download.csdn.net/detail/u012314976/8080883
將下載下來(lái)的壓縮包解壓到網(wǎng)站根目錄中

訪問(wèn)網(wǎng)址http://localhost/basic/requirements.php可以查看自己搭建的環(huán)境是否符合yii的要求

設(shè)置參數(shù)cookieValidationKey,我設(shè)置的是”zhyoulun“,隨便設(shè)置

訪問(wèn)網(wǎng)址http://localhost/basic/web/驗(yàn)證是否一切準(zhǔn)備就緒

開(kāi)始寫(xiě)HelloWorld
第一步、在controllers文件夾下新建ZhyoulunController.php文件
<?phpnamespace appcontrollers;use Yii;use yiiiltersAccessControl;use yiiwebController;use yiiiltersVerbFilter;//類名ZhyoulunController必須和文件名對(duì)應(yīng)html' target='_blank'>class ZhyoulunController extends Controller{ public function actionHelloworld() { return $this->render('helloworld'); }}
第二步、在views文件夾下新建zhyoulun文件夾,這個(gè)需要和ZhyoulunController.php中的“Zhyoulun”對(duì)應(yīng)
第三步、在views/zhyoulun中新建helloworld.php文件,這個(gè)需要和ZhyoulunController類中的公共函數(shù)actionHelloworld()里的“Helloworld”以及return $this->render('helloworld');里的“helloworld”對(duì)應(yīng)
<?phpecho 'hello world!';?>

一種更純凈的展示方式
將return $this->render('helloworld');改為return $this->renderPartial('helloworld');

出處:http://blog.csdn.net/zhyoulun/article/details/40453559
PHP編程鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答
圖片精選