SpeedPHP框架學習 1 基礎及MVC理解

2021-06-10 01:49:47 字數 1226 閱讀 3575

speedphp是乙個以快速學習為基礎的php框架,其架構較為簡單,學習曲線較為簡潔。這裡以乙個cms系統為例,記錄下使用sp的過程。

<?php

define("sp_path",dirname(__file__)."/speedphp");

$spconfig = array(

"db" =>array(

'host' =>'localhost',

'login' =>'root',

'password' =>'root',

'database' =>'test',

),'view' => array(

'enabled' =>true,

'config'=>array(

'left_delimiter'=> '<>',),)

);require(sp_path."/speedphp.php");

sprun();

<?php

class main extends spcontroller

/index.html");

}function write()

}

從index.php過來預設呼叫main方法的index函式,在本例中這個函式首先設定模板名引數(tpl)。再新建乙個model。使用model的findall方法,查詢全部資料庫資訊。最後使用tpl模板顯示結果。上述控制器程式,必須繼承自spcontroller類,方法名就是呼叫的action名。在程式中顯式呼叫時路徑為index.php?c=main&a=write。model如下所示,是和資料庫表同名的類檔案。這個model必須繼承自spmodel,同時設定了主鍵和表名屬性。

<?php

class guestbook extends spmodel

在tpl模板目錄裡的index.html檔案下使用如下所示程式,格式化輸出結果。

<>

<>

<>:

<>

<>

從mvc的角度看,model中的類,相當於模型,它對應資料庫中的每乙個表,且在控制器中進行被操作。而html檔案相當於檢視層,在sp架構中表現問tpl檔案目錄中的檔案,他的程式呼叫等操作在controller層中完成。控制層對應於controller目錄中的類檔案,是程式的核心所在。

學習SpeedPHP 專案筆記一

學習speedphp 框架 完善乙個程式 主要實現 增加業務 修改業務排序 刪除業務 思路 在tpl裡寫靜態頁的 html 在控制器controller裡寫方法 名字要和html 的名字是一樣的 spurl 的 c指的是controller裡的php檔名 a指的是裡面的方法名 所以必須要名字一樣才行...

1 框架基礎搭建

cordova create psdplatform cd psdplatform專案使用vonic作為ui模板,開發者提供了乙個vonic的開發腳手架,即如下 git clone git cd vonic webpack starter npm install g yarn yarn注意事項 在安...

基礎學習1

ctrl 1 標題1 ctrl 2 標題2 快捷鍵 1 ctrl 1 2 3 4 5 6 2 標題 enter ctrl shift i div 語言名字 html enter css enter 列表資料 enter 小黑點 子項資料 enter 空心圓 快捷方式 a b c d enter 姓名...