这几天看阿旭使用QEE,我也心痒不已,正好手头有个项目,正好学习下....又学习了又挣钱了...
QEE不说,还真难,官房提供的快速指南只能说 太简易.....
色色比较熟悉flea,好不容易说服自己使用qee,这次一定要全身而退!!!!!
qee的控制器实现的不错,还实现了命名空间的概念,这个确实很吸引我,加上路由功能....
只是视图这块做的我觉得不咋的,我也很讨厌smarty,我是说纯PHP引擎你也多写点辅助方法啊....
里面 竟然有这种存在,很无语啊,起码你也要像rails,做个什么 样式表标签之类的吧.... 自己来吧,开始...
在helper目录下建立一个x.php文件,里面是色色为自己提供的常规方法....
_basedir = Q::ini('app_config/ROOT_DIR') ;
if (!preg_match("/\\$/i",$this->_basedir))
$this->_basedir .= '/' ;
$this->_baseuri = $_baseuri ;
if (!preg_match("/\\$/i",$_baseuri))
$this->_basedir .= '/' ;
}
static function instance($_baseuri){
static $instance;
if (is_null($instance))
{
if (!empty($_baseuri))
{
$instance = new Helper_X($_baseuri);
}else
die('INVALID CONSTRUCT X');
}
return $instance;
}
private function resIsExist($fpath){
if(file_exists("{$this->_basedir}{$fpath}"))
return true ;
return false ;
}
private function ftimestamp($fpath){
return filemtime("{$this->_basedir}{$fpath}");
}
public function stylesheet_link_tag(){
$css_fpath = "css/%s.css" ;
$params = func_get_args();
foreach ($params as $param){
$fpath = sprintf($css_fpath,$param);
if(!$this->resIsExist($fpath)){
echo sprintf("\n",$this->_baseuri,$fpath);
// QLog::log("未能加载CSS文件: {$this->_basedir}{$fpath}", QLog::WARN);
}
else {
echo sprintf("_baseuri}%s?%d\" type=\"text/css\" media=\"screen\" />\n",
$fpath,$this->ftimestamp($fpath));
}
}
}
public function js_include_tag(){
$js_fpath = "js/%s.js" ;
$params = func_get_args();
foreach ($params as $param){
$fpath = sprintf($js_fpath,$param);
if(!$this->resIsExist($fpath)){
echo sprintf("\n",$this->_baseuri,$fpath);
// QLog::log("未能加载JS文件: {$this->_basedir}{$fpath}", QLog::WARN);
}
else {
echo sprintf("\n",
$fpath,$this->ftimestamp($fpath));
}
}
}
function js_include_ucren($skin='qq',$iscache=false){
$fpath = 'js/engine/boot.js' ;
if(!$this->resIsExist($fpath)){
echo sprintf("\n",$this->_baseuri,$fpath);
QLog::log("未能加载Ucren组件: {$this->_basedir}{$fpath}", QLog::WARN);
}else {
echo sprintf("\n",
$fpath,$this->ftimestamp($fpath),$skin);
}
}
public function js_text($js_code=null){
echo "\n" ;
}
function css_text($css_code=null){
echo "\n" ;
}
/**
* 返回图片地址
*
* @param string $_path
*/
public function img_url($_path,$return = false){
if ($return)
return "{$this->_baseuri}img/{$_path}";
echo "{$this->_baseuri}img/{$_path}";
}
//定义一个函数用于调用FCKeditor
public function call_fck($path=null,$t_set=null,$iname=null,$ivalue=null,$w=null,$h=null){
if (!class_exists('Helper_FCKeditor'))
Q::loadClass('Helper_FCKeditor');
$fcked = Q::singleton('Helper_FCKeditor') ;
$fcked->BasePath = empty($path)? $this->_baseuri . 'js/editor/':$path;
$fcked->ToolbarSet = empty($t_set)?'Basic':$t_set ; //工具栏设置
$fcked->InstanceName = empty($iname)?'test':$iname ;
$fcked->Width = empty($w)?'100%':$w ;
$fcked->Height = empty($h)?'200':$h ;
$fcked->Value = $ivalue;
$fck_area = $fcked->CreateHtml();
return $fck_area ;
}
}
?>
这种 简单的方法,注释我看还是不用写了吧,要看注释的,请看我之前发的色色的FLEAPHP扩展,这些方法基本摘自那里,又简化封装了下....
对应于最后一个fck调用,这里还要在helper目录下建立一个fckeditor.php文件,内容如下:
InstanceName = $instanceName ;
$this->BasePath = './editor/' ;
$this->Width = '100%' ;
$this->Height = '350' ;
$this->ToolbarSet = 'Default' ;
$this->Value = '' ;
$this->Config = array() ;
}
function Create()
{
echo $this->CreateHtml() ;
}
function CreateHtml()
{
$HtmlValue = htmlspecialchars( $this->Value ) ;
$Html = '' ;
if ( $this->IsCompatible() )
{
$File = 'fckeditor.html' ;
$Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
if ( $this->ToolbarSet != '' )
$Link .= "&Toolbar={$this->ToolbarSet}" ;
// Render the linked hidden field.
$Html .= "InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
// Render the configurations hidden field.
$Html .= "InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
// Render the editor IFRAME.
$Html .= "" ;
}
else
{
if ( strpos( $this->Width, '%' ) === false )
$WidthCSS = $this->Width . 'px' ;
else
$WidthCSS = $this->Width ;
if ( strpos( $this->Height, '%' ) === false )
$HeightCSS = $this->Height . 'px' ;
else
$HeightCSS = $this->Height ;
$Html .= "" ;
}
$Html .= '' ;
return $Html ;
}
function IsCompatible()
{
global $HTTP_USER_AGENT ;
if ( isset( $HTTP_USER_AGENT ) )
$sAgent = $HTTP_USER_AGENT ;
else
$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
{
$iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
return ($iVersion >= 5.5) ;
}
else if ( strpos($sAgent, 'Gecko/') !== false )
{
$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
return ($iVersion >= 20030210) ;
}
else
return false ;
}
function GetConfigFieldString()
{
$sParams = '' ;
$bFirst = true ;
foreach ( $this->Config as $sKey => $sValue )
{
if ( $bFirst == false )
$sParams .= '&' ;
else
$bFirst = false ;
if ( $sValue === true )
$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
else if ( $sValue === false )
$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
else
$sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
}
return $sParams ;
}
function EncodeConfig( $valueToEncode )
{
$chars = array(
'&' => '%26',
'=' => '%3D',
'"' => '%22' ) ;
return strtr( $valueToEncode, $chars ) ;
}
}
?>
然后 将 文件拷贝到'js/editor' 下即可....
然后修改控制器,在你自己的控制器中覆盖Controller_Abstract 的_before_render方法即可
/**
* 渲染之前调用
*
* @param QView_Render_PHP
*/
protected function _before_render($response)
{
$x = Helper_X::instance($response->getVar('_BASE_DIR'));
$response->assign('x',$x);
}
然后在你的视图文件中就可以使用了;
_extends('_layouts/default_layout');
?>
_block('contents');
?>
js_include_tag("xx",'jq','bbs');
$x->js_include_ucren();
$x->js_text("
Ucren.onReady(function(){
Ucren.alert('Ucren');
});
");
$x->stylesheet_link_tag("xx",'jq','style');
$x->css_text("body{color:red;}");
?>
_endblock();
?>
运行后页面源代码
QeePHP: 新一代的敏捷开发框架
这里我再给大家抓个图看看啊: