用户
 找回密码
 入住 CI 中国社区
搜索
查看: 8943|回复: 11
收起左侧

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

[复制链接]
发表于 2009-8-15 16:56:54 | 显示全部楼层 |阅读模式
安装步骤:
安装前请在根目录下的index.php增加一行

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

1、下载最新的Smarty,将其中的libs文件夹复制到system/plugins/下,并改名为smarty。
2、下载最新的Fckeditor,将fckeditor文件夹复制到system/plugins/下
3、在system/application/libraries/创建文件:tpl.php增加以下代码:
PHP复制代码
<?php  if ( ! 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复制代码
<?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",""));

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

评分

参与人数 1威望 +5 收起 理由
Hex + 5 原创内容

查看全部评分

 楼主| 发表于 2009-8-15 16:59:55 | 显示全部楼层
超级郁闷,高亮不会用~
发表于 2009-8-15 22:51:20 | 显示全部楼层
我帮楼主修改了语法高亮,呵呵
 楼主| 发表于 2009-8-17 12:27:46 | 显示全部楼层
呵呵,哪位试用了发现不能成功的可以短消息发给我~~这东西挺好的~
唯一不爽的就是文件名有大写(我可以说是相当的不喜欢这样子的——在Linux下大小写敏感了,还不如统一用小写来定文件名呢)
 楼主| 发表于 2009-8-18 19:01:28 | 显示全部楼层
修正一个小BUG
PHP复制代码
 
$fck->BasePath = $sBasePath."system/plugins/fckeditor/";
 
复制代码

改成
PHP复制代码
 
$fck->BasePath = base_url()."system/plugins/fckeditor/";
 
复制代码


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

看来这东西要研究还要花很多时间呢~
发表于 2009-8-19 17:35:44 | 显示全部楼层
楼上的哥们我认识,一个公司的.顶.
发表于 2009-8-19 17:36:31 | 显示全部楼层
那么漂亮的文章,再顶下.
发表于 2009-9-19 18:07:25 | 显示全部楼层
请问可不可以在app目录扩展,不想动system。
发表于 2009-9-28 10:18:50 | 显示全部楼层
好文字,学习
发表于 2009-12-10 22:10:27 | 显示全部楼层
我怎么在 模板文件里面使用smarty 的session不好使 $smarty.session.id 没有东西 这个可以像单独smarty一样使用session??

本版积分规则