<?php
/*燕十八 公益PHP培训
课堂地址:YY频道88354001
学习社区:www.zixue.it */
/*
跟着十八学做商城
自己在做商品添加详细描述的时候调用编辑器的方法
思路:
1:下载好编辑器包(我下的是FCKeditor);
2:放到一个合适的位置(自己觉得放哪合适都可以);
3:在需要显示编辑器的地方引入编辑器类文件,创建编辑器对象,然后生成编辑器(O啦);
*/
<?php
/* 这里是goodsadd.php
goodsadd.html的php引入页面
*/
define('ACC',true);
require_once("../include/initial.php");
require_once(ROOT.'/view/admin/templates/goodsadd.html');
//引入编辑器
?>
<?php
/*
这里是写在goodsadd.html里面的
*/
//通过$_SERVER['PHP_SELF']找到当前路径
$sBasePath = $_SERVER['PHP_SELF'] ;
//通过substr 和 strpos 函数找到编辑器的路径,我的编辑器是放在include文件夹下的edit目录下.
$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "Admin" )).'include/edit/';
//创建编辑器对象
$oFCKeditor = new FCKeditor('FCKeditor1') ;
//给对象默认路径赋值
$oFCKeditor->BasePath = $sBasePath ;
//编辑器的初始值
$oFCKeditor->Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
//生成编辑器
$oFCKeditor->Create() ;
?>
<?php
/* 这里是init.php
当 $oFCKeditor = new FCKeditor('FCKeditor1') ;new的时候,会调用init.php
的_autoload()方法因此需要在这里引入编辑器的类文件
在__autoload()方法里添加一个逻辑
*/
function __autoload($class){
if(substr($class,-5)=='Model'){
$table = substr($class,0,-5);
require_once (ROOT."Model/".$class.".class.php");
}else if($class=='FCKeditor'){
require_once (ROOT.'/include/edit/fckeditor.php');
}else{
require_once (ROOT."Include/".$class.".class.php");
}
}
<?php
/*
完成了,编辑调用成功!拿出来分享下,不足之处望指出,谢谢!
*/