寫了幾篇LotusPhp,一直沒有跑個程序,感覺好像步驟有點錯,所以先上個經典的Demo,HelloWorld吧
先按推薦目錄建好文件夾,如果懶的建,下面有下載的Demo包,解壓就可以用,因為簡單,也沒有用樣式,所以解壓到任何目錄都可以跑的起來。
先不用考慮怎么用,關鍵的文件其實就是
runtime/app/frontend/action/default-index.php和runtime/app/frontend/view/default-index.php
Demo主要應用了MVC,及一些基本的文件夾設置,以后的范例基本會在Demo的基礎上建立
現在來書寫index.php的內容,這個是所有程序文件的引導文件,同樣LotusPhp也是單入口
<?php
ob_start();
header('Content-Type:text/html;charset=UTF-8');
//防止直接打開的參數
define("LOTUS", true);
//定義根目錄
define("ROOT",dirname(__FILE__));
$lotusHome = ROOT.'/framework/';
include($lotusHome . "Lotus.php");
$lotus = new Lotus;
//是否處於開發模式
$lotus->devMode = true;
//緩存目錄
$lotus->defaultStoreDir = ROOT.'/cache/';
$lotus->option['proj_dir'] = ROOT.'/runtime/';
$lotus->option['app_name'] = 'frontend';
$lotus->init();
接下來書寫
runtime/app/frontend/action/default-index.php
<?php
class DefaultIndexAction extends LtAction
{
public function execute()
{
$this->responseType = 'tpl';
$this->data='HelloWorld';
}
}
runtime/app/frontend/view/default-index.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{$this->data}</title>
</head>
<body>
{$this->data}
</body>
</html>
一些常見的錯誤分析:
Warning: mkdir() [function.mkdir]: File exists in E:\web\framework\StoreFile.php on line 76 Warning: file_put_contents(C:/Windows/TEMP/Lt-parsed-token-1511998383/3d/9b/3d9b92c67d278abd5ad503281dd465fa) [function.file-put-contents]: failed to open stream: No such file or directory in E:\web\framework\StoreFile.php on line 78
這種情況多半是由於php版本老,是5.2的或者是會員權限不夠,無法在臨時目錄生成文件造成的,最好的解決辦法是修改會員權限或者是替換為5.3以上php版本,如果無法解決,私信我即可,我看到會回復
Warning: include(E:\web\runtime\/conf/conf_dev.php) [function.include]: failed to open stream: No such file or directory in E:\web\runtime\app\frontend\conf\conf_dev.php on line 6
這種情況是因為conf目錄建的不對或者是conf.php和conf_dev.php文件導致,下面列出這2個文件的內容,所有的lotusphp應用目錄下,都應該有符合規范的conf目錄,子目錄和這2個文件
conf.php
<?php
$config = array();
foreach(glob(dirname(__FILE__) . '/standard/*.php') as $confFile)
{
if (__FILE__ != $confFile)
{
include($confFile);
}
}
return $config;
conf_dev.php
<?php
/**
* 開發模式下先讀取standard配置,
* 然后讀取dev配置,並覆蓋standard的部分配置
*/
include(dirname(__FILE__) .'/conf.php');
foreach(glob(dirname(__FILE__) . '/dev/*.php') as $confFile)
{
if (__FILE__ != $confFile)
{
include($confFile);
}
}
return $config;
如果都正確,那這時候運行index.php就會出現熟悉的HelloWorld了,搞定。
附件下載:demo.rar
