techpush / bella.php
此包已被弃用且不再维护。未建议替代包。
构建Web应用的简单库
dev-master
2014-12-07 14:19 UTC
This package is not auto-updated.
Last update: 2020-01-20 03:31:46 UTC
README
一个轻量级的PHP库,用于快速构建Web应用。
BellaPHP是一个非常简单的工具包,可以帮助你处理模块化、路由、数据库、curl、文件/目录、设备检测等功能。
使用composer.phar轻松安装bella.php
"require": {
"techpush/bella.php": "dev-master"
}
网站目录结构可能看起来像这样(但你可以按任何你想要的方式定义)
app/
controllers/
article.php
models/
article.php
views/
article.php
conf/
development/
production/
public/
css/
fonts/
images/
js/
storage/
cache/
log/
vendor/
/techpush/
bella.php/
src/
在/app/controllers/article.php中,你定义控制器如下
<?php
namespace Bella;
class articleController extends Coordinator {
public function parse(){
$this->route('/:alias/:id', function($alias, $id){
if(!!$id){
$h = $this->loadHandler();
return $h->run($alias, $id);
}
});
return Bella::end();
}
}
在/app/models/article.php中,你定义相关模型如下
<?php
namespace Bella;
class articleModel extends Handler {
public function run($alias, $id){
$conf = Config::get('api');
$api = new API($conf->baseURL);
$data = $api->get('api/read', ['id'=>$id]);
if(!!$data){
$view = $this->view;
// set layout to render as HTML
// it will look at /app/views/layouts/article.html
$view->setLayout('article');
// register the CSS files
$view->registerCSS(['base.css', 'default.css', 'article.css', 'fontello.css']);
// register the javascript libraries
$view->registerLibs(['highlight.pack', 'socialite.min']);
// set metadata to the page
$view->setHeader([
'title' => $data->title,
'url' => $data->link,
'canonical' => $data->canonical,
'creator' => $data->author,
'description' => $data->description,
'image' => $data->image
]);
return $view->render(['article' => $data]);
}
return Bella::end();
}
}
BellaPHP使用Handlebars作为模板引擎,/app/views/layouts/article.html看起来像这样
<div class="article-title" itemprop="name">{{{article.title}}}</div>
<div class="article-summary">
<span class="article-pubTime" itemprop="datePublished">
{{article.datetime}}
</span>,
<span itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">{{{article.author}}}</span>
</span>
<div class="article-content" itemprop="articleBody">{{{article.content}}}</div>
要了解现实世界的应用,请访问我的网站:http://techpush.net/