|
加載框架文件》加載參數(shù)設(shè)置對(duì)象》進(jìn)行初始化設(shè)置》加載項(xiàng)目設(shè)置參數(shù)》獲取控制器及控制器方法》執(zhí)行控制器事件
使用實(shí)例為:
復(fù)制代碼 代碼如下:
<?php
class DefaultController extends AppController
{
protected $components = array('smarty');
/** 默認(rèn)事件(方法) */
public function index()
{
$db_test = M('members'); //加載并實(shí)例化一個(gè)模型
/** 添加數(shù)據(jù) */
$data = array(
'title' => '寫(xiě)入測(cè)試',
'body' => '寫(xiě)入的內(nèi)容',
);
$result = $db_test->create($data);
if(FALSE != $result)
{
dump("<p><strong>exampel 1:</strong><br />數(shù)據(jù)寫(xiě)入成功!</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>寫(xiě)入成功!<br />");
}
}
dump("</p>");
/** 更新數(shù)據(jù) */
$data = array('title'=>'修改數(shù)據(jù)標(biāo)題', '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ù)查詢(xún),使用連貫的操作符 */
$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'); //加載并實(shí)例化一個(gè)系統(tǒng)模型
$im->th_width = 200;
$im->th_height = 150;
$im->thumb($file, null, false);
}
/** 另一個(gè)控制器事件 */
public function admin()
{
dump($this);
$this->shownav();
}
/** 另一個(gè)控制器事件 */
public function info()
{
$this->shownav();
phpinfo();
}
/** 這是一個(gè)內(nèi)部事件,無(wú)法從瀏覽器地址進(jìn)行訪問(wèn) */
private function shownav()
{
echo '<a href="/">訪問(wèn)默認(rèn)事件</a> | <a href="?a=admin">訪問(wèn)事件 admin</a> | <a href="?a=info">訪問(wèn)事件 info</a>';
}
}
?>




單個(gè)空間多個(gè)站點(diǎn)的實(shí)現(xiàn)
復(fù)制代碼 代碼如下:
<?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.jb51.NET/codes/20169.html
php技術(shù):MayFish PHP的MVC架構(gòu)的開(kāi)發(fā)框架,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。