站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
建站程序
开发
服务器
办公软件
开发教程
服务器教程
软件使用教程
运营教程
热门电子书
WordPress教程
宝塔面板教程
CSS教程
Shopify教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
ThinkSNS-应用开发范例-增加应用后台
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
<span style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> [[ThinkSNS|上一页]]</span> <div style="clear:both;"></div> [[ThinkSNS]]1.6 为应用增加管理后台的方法很简单,直接在应用的Action 目录下增加AdminAction.class.php 文件,定义一个AdminAction 类,只要让它继承Administrator 类ThinkSNS 就可以自动识别为后台管理类。代码如下所示: <pre> <?php /** * IndexAction * 礼品应用的后台操作 * * @package default * @version $id$ * @copyright 2009-2011 水上铁 * @author 水上铁<wxm201411@163.com> * @license PHP Version 5.2 {@link www.sampeng.cn} */ class AdminAction extends Administrator { var $category; //礼品类型模型 var $gift; //礼品模型 /** * 构造函数 * * 获取礼品模型,礼品类型模型 * 获取礼品配置信息并赋值给模板 */ function _initialize(){ $this->category = D('GiftCategory'); $this->gift = D('Gift'); $config = D('AppConfig')->getConfig(); $this->assign('config',$config); } /** * 礼物中心 * */ function index() { $categoryId = intval($_GET['categoryId']); if($categoryId){ $map['categoryId'] = $categoryId; } $list = $this->gift->where($map)->order('id desc')->findPage(10); $this->assign("list",$list); $types = $this->api->CreditSetting_getCreditType(); $this->assign("types",$types); $this->display(); } /* *编辑礼物分类 */ function edit() { $id = (int)$_REQUEST['id']; $vo = $this->gift->find($id); if(!$vo) { $this->error("无法找到对象!"); return; } $catagorys = $this->category->findAll(); $this->assign('categorys',$catagorys); $this->assign("vo",$vo); $this->display(); } /* *显示增加礼品页面 */ function add() { $catagorys = $this->category->findAll(); $this->assign('categorys',$catagorys); $this->display(); } /* *增加礼品到数据库 */ function insert() { $path = 'Tpl/default/Public/gift/'; $info = $this->_upload($path); if(!is_array($info))$this->error("上传出错! ".$info); if($info&&is_array($info)){ $imgname = $info[0]['savename']; $model = $this->gift; if(false === $model->create()) { $this->error($model->getError()); } //保存当前数据对象 $model->img = $imgname; $model->cTime = time(); $id = $model->add(); if($id) { //保存成功 //成功提示 $this->success(L('_INSERT_SUCCESS_')); }else { //失败提示 $this->error(L('_INSERT_FAIL_')); } } } /* *更新礼品到数据库 */ function update() { $path = 'Tpl/default/Public/gift/'; $info = $this->_upload($path); if($info && is_array($info)){ $imgname = $info[0]['savename']; } $model = $this->gift; if(false === $model->create()) { $this->error($model->getError()); } //保存当前数据对象 if($imgname){ $model->img = $imgname; } $id = $model->save(); if($id) { //保存成功 //成功提示 $this->success(L('_UPDATE_SUCCESS_')); }else { //失败提示 $this->error(L('_UPDATE_FAIL_')); } //} } /** +---------------------------------------------------------- * 默认删除操作 */ public function delete() { //删除指定记录 $model = $this->gift; if(!empty($model)) { $id = $_REQUEST['id']; if(isset($id)) { if($model->delete($id)){ $this->assign("message",'删除成功!'); $vo = $model->find($_GET['id']); $this->assign("jumpUrl",$this->getReturnUrl()); }else { $this->error("删除失败!"); } }else { $this->error('非法操作'); } $this->forward(); } } /** +---------------------------------------------------------- * 默认锁定操作 * */ function forbid() { $model = $this->gift; $condition = 'id IN ('.$_GET['id'].')'; if($model->forbid($condition)){ $this->assign("message",'状态禁用成功!'); $vo = $model->find($_GET['id']); $this->assign("jumpUrl",$this->getReturnUrl()); }else { $this->assign('error', '状态禁用失败!'); } $this->forward(); } /** +---------------------------------------------------------- * 默认恢复操作 */ function resume() { //恢复指定记录 $model = $this->gift; $condition = 'id IN ('.$_GET['id'].')'; if($model->resume($condition)){ $this->assign("message",'状态恢复成功!'); $vo = $model->find($_GET['id']); $this->assign("jumpUrl",$this->getReturnUrl()); }else { $this->assign('error', '状态恢复失败!'); } $this->forward(); } /* *获取返回地址 */ function getReturnUrl() { return base64_decode($_REQUEST['returnUrl']); } /* *执行单图上传操作 */ protected function _upload($path,$save_name,$is_replace,$is_thumb,$thumb_name,$thumb_max_width) { if(!checkDir($path)){ return '目录创建失败: '.$path; } import("ORG.Net.UploadFile"); $upload = new UploadFile(); //设置上传文件大小 $upload->maxSize = '2000000' ; //设置上传文件类型 $upload->allowExts = explode(',',strtolower('jpg,gif,png,jpeg,bmp')); //存储规则 $upload->saveRule = 'uniqid'; //设置上传路径 $upload->savePath = $path; //保存的名字 $upload->saveName = $save_name; //是否缩略图 $upload->thumb = $is_thumb; $upload->thumbMaxWidth = $thumb_max_width; $upload->thumbFile = $thumb_name; //存在是否覆盖 $upload->uploadReplace = $is_replace; //执行上传操作 if(!$upload->upload()) { //捕获上传异常 return $upload->getErrorMsg(); }else{ //上传成功 return $upload->getUploadFileInfo(); } } /* *更新礼品配置信息 */ function doEditConfig(){ $types = $this->api->CreditSetting_getCreditType(); foreach($_POST as $k=>$v){ $credit = t($v); $map['creditType'] = $credit; $map['creditName'] = $types[$credit]; } $result = D('AppConfig')->editConfig($map); if($result){ $this->success('更新成功!'); }else{ $this->error('更新失败!'); } } } ?> </pre> '''注意''':其中的{APP_URL}是指应用的网址,如果直接使用它本身的话程序会自动解释成绝对[[网址]],还有一个好处就是网站转移的时候这些信息都不需要修改,程序会自动解释出新的网址赋值给它。当然,你也可以使用绝对网址。登录后台后进入“应用=》应用管理=》添加应用”点击‘安装’应用就可以了。在所有应用列表里还可以使用上移下移调整应用的位置。然后更新一下系统缓存就可以在前台的应用列表中看到我们的礼品应用了。 ==参考资料== *[http://www.thinksns.com 参考来源] [[category:ThinkSNS]]
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)