qinggan 发表于 2009-8-15 16:56:54

终于将插件Smarty+Fckeditor加进去了

安装步骤:
安装前请在根目录下的index.php增加一行

define('ROOT',dirname(__FILE__)."/");

1、下载最新的Smarty,将其中的libs文件夹复制到system/plugins/下,并改名为smarty。
2、下载最新的Fckeditor,将fckeditor文件夹复制到system/plugins/下
3、在system/application/libraries/创建文件:tpl.php增加以下代码:
<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(BASEPATH.'plugins/smarty/Smarty.class.php');
class Tpl extends Smarty
{
function tpl()
{
parent::Smarty();
$this->template_dir = ROOT.'tpl';
$this->compile_dir = ROOT.'cache/tpl_c';
$this->left_delimiter="{"; //定义左边界符
$this->right_delimiter="}"; //定义右边界符
//$this->debugging = true;
}
}
?>
4、在system/plugins/目录下增加文件:fckeditor_pi.php 文件,代码如下:
<?php
#===========================================================
# Filename: system/plugins/fckeditor_pi.php
# Note : 加配编辑器
# Version : 3.0
# Author: qinggan
# Update: 2009-08-15
#===========================================================
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if (!function_exists('Fckeditor'))
{
function Fckeditor($var="content",$content="",$toolbar="Default",$width="700px",$height="500px")
{
require_once(BASEPATH."plugins/fckeditor/fckeditor.php");
$var = $var ? $var : "content";
$fck = new FCKeditor($var) ;//获得一个变量信息
$sBasePath = $_SERVER['PHP_SELF'] ;
$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "_samples" ) ) ;
$fck->BasePath = $sBasePath."system/plugins/fckeditor/";
$fck->Value = $content;
$fck->Config['AutoDetectLanguage'] = false;
$fck->Config['DefaultLanguage'] = "zh-cn";
$fck->Config['ToolbarStartExpanded'] = true;
$fck->ToolbarSet = $toolbar != "Default" ? "Basic" : "Default";
$fck->Width = $width ? $width : "543px";
$fck->Height = $height ? $height : "300px";
$fck->Config['EnableXHTML'] = true;
$fck->Config['EnableSourceXHTML'] = true;
return $fck->CreateHtml();
}
}
?>

5、自动加载:
修改文件:system/application/config/autoload.php
修改:$autoload['libraries'] = array('tpl');   //如果之前已有新的类,请附加在后面即可。
修改:$autoload['plugin'] = array("fckeditor");   //同上
6、调用方法:
1)、使用Smarty插件
直接在使用
$this->tpl->display("模板.html");
$this->tpl->assign("变量ID","值");
//所有其他用法类似
2)、使用Fckeditor编辑器
直接使用函数
Fckeditor('变量名','值','编辑器类型','宽','高');
例如:
Fckeditor("content","123456789","Default","700px","500px");
可以缩略写成:
Fckeditor("content","123456789");

要附加给模板,使用这样子使用
$this->tpl->assign("editor",Fckeditor("content",""));

以上功能经情感验证成功通过~~~瞄瞄滴,折腾了我好几天了

qinggan 发表于 2009-8-15 16:59:55

超级郁闷,高亮不会用~:(

Hex 发表于 2009-8-15 22:51:20

我帮楼主修改了语法高亮,呵呵

qinggan 发表于 2009-8-17 12:27:46

呵呵,哪位试用了发现不能成功的可以短消息发给我~~这东西挺好的~
唯一不爽的就是文件名有大写(我可以说是相当的不喜欢这样子的——在Linux下大小写敏感了,还不如统一用小写来定文件名呢)

qinggan 发表于 2009-8-18 19:01:28

修正一个小BUG

$fck->BasePath = $sBasePath."system/plugins/fckeditor/";

改成

$fck->BasePath = base_url()."system/plugins/fckeditor/";


才能在index.php/参数/……下正常使用~

看来这东西要研究还要花很多时间呢~

wangwen208 发表于 2009-8-19 17:35:44

楼上的哥们我认识,一个公司的.顶.{:3_46:}

wangwen208 发表于 2009-8-19 17:36:31

那么漂亮的文章,再顶下.

afish1984 发表于 2009-9-19 18:07:25

请问可不可以在app目录扩展,不想动system。

xiaocai_2009 发表于 2009-9-28 10:18:50

好文字,学习

frui 发表于 2009-12-10 22:10:27

我怎么在 模板文件里面使用smarty 的session不好使 $smarty.session.id 没有东西 这个可以像单独smarty一样使用session??
页: [1] 2
查看完整版本: 终于将插件Smarty+Fckeditor加进去了