國產PHP開發架構myqee新手快速入門教程,myqee入門教程
一.環境.
筆者的環境是win7 32bit 旗艦版.用的xampp1.7.4(1.8.x版的php版本太高,個人覺得php 5.3X更實用些)+mq最新版.重點是配置虛擬機器,
參考了http://www.bkjia.com/article/52123.htm
本機xampp安裝在D盤,給出我的配置:虛擬機器組態檔路徑 D:\xampp\apache\conf\extra\httpd-vhosts
複製代碼 代碼如下:
#mq
DocumentRoot "D:/xampp/htdocs/mq/"
ServerName mq
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
DocumentRoot "D:/xampp/htdocs/"
ServerName localhost
host設定檔位置
C:\Windows\System32\drivers\etc\hosts.ics
本機沒有找到 hosts ,改hosts.ics也是可以的.
二.建立一個myqee項目
1.下載最新 版myqee,github 你懂的.
解壓到D:/xampp/htdocs/mq檔案夾下(與虛擬機器設定一致).
修改config.new.php 為config.php
還有需要一個.htacess ,我用github 下載下來的一直不行,需要用官方文檔寫的那個.內容如下
複製代碼 代碼如下:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [PT,L]
copy一份到wwwroot目錄下.
a.建立 一個項目,開啟根目錄的config.php,新增一個s項目,
配置如下(放在預設配置之前)
複製代碼 代碼如下:
's' => array
(
'name' => '預設項目', //名稱
'dir' => 's', //目錄
'isuse' => true, //是否啟用
'url' => '/',
),
b.projects下面建立 目錄s ,為了方便,直接複製defautl並重新命名.
在s目錄下controllers中建立 一個最簡單的控制器 helloworld.controller.php
內容如下
複製代碼 代碼如下:
<?php
class Controller_HelloWorld extends Controller
{
/**
* 測試
*/
public function action_default()
{
echo 'helloworld';
}
}
開啟瀏覽器,輸入mq/index.php/helloworld,看到hellowold,成功.
在開發環境中,建議開啟myqee的debug功能,在php.ini加入
複製代碼 代碼如下:
;[MyQEE]
myqee.debug=On
配合firefox +firebug使用.
三.顯示資料庫中的內容.
hello world太簡單了,以至於在實際開發中沒有什麼意義,趁熱打鐵.來點乾貨,從資料庫讀取資料,並顯示在對應的視圖中.
a.建立config.php放在s 根目錄下並寫入對應的資料庫配置.內容如下:
複製代碼 代碼如下:
<?php
/**database config*/
$config['database']['default'] = array
(
'type' => 'MySQL',
'connection' => array
(
'hostname' => '127.0.0.1',
'database' => 'mq',
'username' => 'mq',
'password' => '123456', 'persistent' => false,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => false,
'profiling' => true,
);
這裡我在mysql中建立了一個mq庫 ,並建了一張表wh_list
wh_list的ddl如下,(內容自己添加).
複製代碼 代碼如下:
CREATE TABLE `wh_list` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
b.model整起.
在s目錄下建立models目錄,並建立 一個wh.model.php內容如下:
複製代碼 代碼如下:
<?php
class Model_Wh extends Model
{
static function get_list()
{
$db = Database::instance();
$sql = 'select * FROM wh_list';
$arr = $db->query($sql)->as_array();
return $arr;
}
}
修改下上面的helloworld控制器.內容修改如下:
複製代碼 代碼如下:
<?php
class Controller_HelloWorld extends Controller
{
/**
* 測試
*/
public function action_default()
{
$view = new View('wh');
$arr = Model_Wh::get_list();
$view->set('wh', $arr);
$view->render();
}
}
別激動,如果在瀏覽刷剛才的mq/index.php/helloworld,肯定會報錯的,視圖沒有.
在views,建立 wh.view.php
內容如下:
複製代碼 代碼如下:
<?php foreach($wh as $w){?>
<?php echo $w['name'] ?>
<?php }?>
重新整理下,就能看到wh_list 表的`name`列內容了.
呵呵,是不是很有成就感.
新手入門的教程先寫到這裡,聲明下,這個只是給新手快速入門感受架構之用.
國產的PHP快速開發架構哪個比較好?支援ajax與許可權管理的
php架構只是個寫的比較規範的類,ajax和許可權管理的你要自己寫類。
我個人推薦 thinkphp 因為這個網上的教程比較多,我就在學這個架構。
有一個Qeephp問題想教廖老大 - PHP架構開發
ror 是用 ruby 開發的架構,qeephp 是用 php 開發的架構。。。不存在什麼原生快速開發語言
http://www.bkjia.com/PHPjc/840644.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/840644.htmlTechArticle國產PHP開發架構myqee新手快速入門教程,myqee入門教程 一.環境. 筆者的環境是win7 32bit 旗艦版.用的xampp1.7.4(1.8.x版的php版本太高,個人覺得ph...