MayFish PHP的MVC架構(gòu)的開發(fā)框架
更新時間:2009年08月13日 14:49:01 作者:
MayFish,一款PHP的MVC架構(gòu)的開發(fā)框架。小巧精煉。歡迎大家測試和使用,歡迎大家對他的發(fā)展提出更好的建議。
框架工作流程:
加載框架文件》加載參數(shù)設置對象》進行初始化設置》加載項目設置參數(shù)》獲取控制器及控制器方法》執(zhí)行控制器事件
使用實例為:
<?php
class DefaultController extends AppController
{
protected $components = array('smarty');
/** 默認事件(方法) */
public function index()
{
$db_test = M('members'); //加載并實例化一個模型
/** 添加數(shù)據(jù) */
$data = array(
'title' => '寫入測試',
'body' => '寫入的內(nèi)容',
);
$result = $db_test->create($data);
if(FALSE != $result)
{
dump("<p><strong>exampel 1:</strong><br />數(shù)據(jù)寫入成功!</p>");
}
/** 添加多條數(shù)據(jù) */
dump("<p><strong>exampel 2:</strong><br />");
$data = array(
array('title'=>'數(shù)據(jù)1', 'body'=>'內(nèi)容1'),
array('title'=>'數(shù)據(jù)2', 'body'=>'內(nèi)容2'),
array('title'=>'數(shù)據(jù)3', 'body'=>'內(nèi)容3'),
array('title'=>'數(shù)據(jù)4', 'body'=>'內(nèi)容4'),
array('title'=>'數(shù)據(jù)5', 'body'=>'內(nèi)容5'),
);
foreach($data as $item)
{
$result = $db_test->create($item);
if(FALSE != $result)
{
dump("數(shù)據(jù)<strong>".$item['title']."</strong>寫入成功!<br />");
}
}
dump("</p>");
/** 更新數(shù)據(jù) */
$data = array('title'=>'修改數(shù)據(jù)標題', 'body'=>'修改數(shù)據(jù)內(nèi)容');
$result = $db_test->where(array('id'=>3))->update($data);
if(FALSE != $result)
{
dump("<p><strong>exampel 3:</strong><br />數(shù)據(jù)更新成功!</p>");
}
/** 刪除數(shù)據(jù) */
$result = $db_test->where("id=5")->remove();
if(FALSE != $result)
{
dump("<p><strong>exampel 3:</strong><br />數(shù)據(jù)刪除成功!</p>");
}
/** 執(zhí)行數(shù)據(jù)查詢,使用連貫的操作符 */
$db_test->where(array('id'=>12, 'action'=>1))
->order("`id` DESC")
->fields("id,name,action")
->findAll();
$this->shownav();
}
//圖片處理事件
public function image()
{
$file = Configure::read('app_path').'/yagas/K750c_small_06.jpg';
$im = M('SYS', 'image'); //加載并實例化一個系統(tǒng)模型
$im->th_width = 200;
$im->th_height = 150;
$im->thumb($file, null, false);
}
/** 另一個控制器事件 */
public function admin()
{
dump($this);
$this->shownav();
}
/** 另一個控制器事件 */
public function info()
{
$this->shownav();
phpinfo();
}
/** 這是一個內(nèi)部事件,無法從瀏覽器地址進行訪問 */
private function shownav()
{
echo '<a href="/">訪問默認事件</a> | <a href="?a=admin">訪問事件 admin</a> | <a href="?a=info">訪問事件 info</a>';
}
}
?>



單個空間多個站點的實現(xiàn)
<?php
header('Content-type:text/html; charset=utf-8');
include_once('./MayFish/init.php'); //加載MFS框架
$domain = $_SERVER['HTTP_HOST'];
switch($domain) {
case 's1.xinxi169.com.cn':
Configure::write('app_name', 'app');
Configure::write('app_path', dirname(__FILE__).'/app');
break;
case 'www.aike8.cn':
case 'aike8.cn':
Configure::write('app_name', 'aike8');
Configure::write('app_path', dirname(__FILE__).'/aike8');
break;
}
$app = new application();
$app->run();
?>
下載地址 http://www.dbjr.com.cn/codes/20169.html
加載框架文件》加載參數(shù)設置對象》進行初始化設置》加載項目設置參數(shù)》獲取控制器及控制器方法》執(zhí)行控制器事件
使用實例為:
復制代碼 代碼如下:
<?php
class DefaultController extends AppController
{
protected $components = array('smarty');
/** 默認事件(方法) */
public function index()
{
$db_test = M('members'); //加載并實例化一個模型
/** 添加數(shù)據(jù) */
$data = array(
'title' => '寫入測試',
'body' => '寫入的內(nèi)容',
);
$result = $db_test->create($data);
if(FALSE != $result)
{
dump("<p><strong>exampel 1:</strong><br />數(shù)據(jù)寫入成功!</p>");
}
/** 添加多條數(shù)據(jù) */
dump("<p><strong>exampel 2:</strong><br />");
$data = array(
array('title'=>'數(shù)據(jù)1', 'body'=>'內(nèi)容1'),
array('title'=>'數(shù)據(jù)2', 'body'=>'內(nèi)容2'),
array('title'=>'數(shù)據(jù)3', 'body'=>'內(nèi)容3'),
array('title'=>'數(shù)據(jù)4', 'body'=>'內(nèi)容4'),
array('title'=>'數(shù)據(jù)5', 'body'=>'內(nèi)容5'),
);
foreach($data as $item)
{
$result = $db_test->create($item);
if(FALSE != $result)
{
dump("數(shù)據(jù)<strong>".$item['title']."</strong>寫入成功!<br />");
}
}
dump("</p>");
/** 更新數(shù)據(jù) */
$data = array('title'=>'修改數(shù)據(jù)標題', 'body'=>'修改數(shù)據(jù)內(nèi)容');
$result = $db_test->where(array('id'=>3))->update($data);
if(FALSE != $result)
{
dump("<p><strong>exampel 3:</strong><br />數(shù)據(jù)更新成功!</p>");
}
/** 刪除數(shù)據(jù) */
$result = $db_test->where("id=5")->remove();
if(FALSE != $result)
{
dump("<p><strong>exampel 3:</strong><br />數(shù)據(jù)刪除成功!</p>");
}
/** 執(zhí)行數(shù)據(jù)查詢,使用連貫的操作符 */
$db_test->where(array('id'=>12, 'action'=>1))
->order("`id` DESC")
->fields("id,name,action")
->findAll();
$this->shownav();
}
//圖片處理事件
public function image()
{
$file = Configure::read('app_path').'/yagas/K750c_small_06.jpg';
$im = M('SYS', 'image'); //加載并實例化一個系統(tǒng)模型
$im->th_width = 200;
$im->th_height = 150;
$im->thumb($file, null, false);
}
/** 另一個控制器事件 */
public function admin()
{
dump($this);
$this->shownav();
}
/** 另一個控制器事件 */
public function info()
{
$this->shownav();
phpinfo();
}
/** 這是一個內(nèi)部事件,無法從瀏覽器地址進行訪問 */
private function shownav()
{
echo '<a href="/">訪問默認事件</a> | <a href="?a=admin">訪問事件 admin</a> | <a href="?a=info">訪問事件 info</a>';
}
}
?>



單個空間多個站點的實現(xiàn)
復制代碼 代碼如下:
<?php
header('Content-type:text/html; charset=utf-8');
include_once('./MayFish/init.php'); //加載MFS框架
$domain = $_SERVER['HTTP_HOST'];
switch($domain) {
case 's1.xinxi169.com.cn':
Configure::write('app_name', 'app');
Configure::write('app_path', dirname(__FILE__).'/app');
break;
case 'www.aike8.cn':
case 'aike8.cn':
Configure::write('app_name', 'aike8');
Configure::write('app_path', dirname(__FILE__).'/aike8');
break;
}
$app = new application();
$app->run();
?>
下載地址 http://www.dbjr.com.cn/codes/20169.html
您可能感興趣的文章:
- java學生信息管理系統(tǒng)MVC架構(gòu)詳解
- SpringMVC架構(gòu)的項目 js,css等靜態(tài)文件導入有問題的解決方法
- thinkPHP5.0框架整體架構(gòu)總覽【應用,模塊,MVC,驅(qū)動,行為,命名空間等】
- SpringMVC互聯(lián)網(wǎng)軟件架構(gòu)REST使用詳解
- mvc架構(gòu)實現(xiàn)商品的購買(二)
- ASP.NET MVC5網(wǎng)站開發(fā)之展示層架構(gòu)(五)
- ASP.NET?MVC5網(wǎng)站開發(fā)之業(yè)務邏輯層的架構(gòu)和基本功能(四)
- ssi框架學習總結(jié)(mvc三層架構(gòu))
- PHP MVC模式在網(wǎng)站架構(gòu)中的實現(xiàn)分析
- SpringMVC MVC架構(gòu)原理及實現(xiàn)方法詳解
相關(guān)文章
php獲取四位字母和數(shù)字的隨機數(shù)的實現(xiàn)方法
這篇文章主要介紹了php做程序開發(fā)的過程中,我們很多時候會在登錄界面或者評論界面做一些四位數(shù)的驗證碼,需要的朋友可以參考下2015-01-01PHP的serialize序列化數(shù)據(jù)以及JSON格式化數(shù)據(jù)分析
這篇文章的內(nèi)容是PHP的serialize序列化數(shù)據(jù)以及JSON格式化數(shù)據(jù)分析,需要的朋友可以參考下2015-10-10