homepagePHP/app/Admin/Controller/IntroduceController.class.php

127 lines
3.5 KiB
PHP

<?php
namespace Admin\Controller;
use Gy_Library\GyListController;
use Gy_Library\DBCont;
use Qscmf\Builder\FormBuilder;
use Qscmf\Builder\ListBuilder;
use Qscmf\Builder\TSubBuilder;
/*
* 关键词
*/
class IntroduceController extends GyListController
{
use TSubBuilder;
private $news_index = "tz_news_id";
public function index()
{
$map = [];
$model = D('Introduce');
$count = $model->getListForCount();
// }
$order = 'id desc';
$data_list = $model->getListForPage($map, 1, 3, $order);
$builder = new ListBuilder();
$builder = $builder->setMetaTitle('简介管理');
$builder
->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index')
// ->addSearchItem('news_name', 'select_text', '单行输入', array('name' => '名称'))
->addTableColumn('belong_to', '模块')
->addTableColumn('content', '内容')
->addTableColumn('right_button', '操作', 'btn')
->setTableDataList($data_list) // 数据列表
->addRightButton('edit') // 添加编辑按钮
->display();
}
public function edit($id)
{
if (IS_POST) {
parent::autoCheckToken();
$m_id = I('post.id');
$data = I('post.');
$model = D('Introduce');
if (!$m_id) {
E('缺少内容ID');
}
$ent = $model->getOne($m_id);
if (!$ent) {
E('不存在内容');
}
$ent['content'] = $data['content'];
if ($model->createSave($ent) === false) {
$this->error($model->getError());
} else {
$this->success('修改成功', U('index'));
}
} else {
$model = D('Introduce');
$info = $model->getOne($id);
$builder = new FormBuilder();
$builder->setMetaTitle('修改简介')
->setPostUrl(U('edit'))
->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index')
->addFormItem('id', 'hidden', 'ID')
// belong_to 不允许修改
->addFormItem('belong_to', 'text', '模块', '请勿修改此字段')
->addFormItem('content', 'textarea', '内容')
->setFormData($info)
->display();
}
}
public function forbid()
{
$ids = I('ids');
if (!$ids) {
$this->error('请选择要禁用的数据');
}
$r = parent::_forbid($ids);
if ($r !== false) {
// sysLogs('新闻分类id: ' . $ids . ' 禁用');
$this->success('禁用成功', U(CONTROLLER_NAME . '/index'));
} else {
$this->error($this->_getError());
}
}
public function resume()
{
$ids = I('ids');
if (!$ids) {
$this->error('请选择要启用的数据');
}
$r = parent::_resume($ids);
if ($r !== false) {
$this->success('启用成功', U(CONTROLLER_NAME . '/index'));
} else {
$this->error($this->_getError());
}
}
public function delete()
{
$ids = I('ids');
if (!$ids) {
$this->error('请选择要删除的数据');
}
$r = parent::_del($ids);
if ($r === false) {
$this->error($this->_getError());
} else {
$this->success('删除成功', U(MODULE_NAME . '/' . CONTROLLER_NAME . '/index'));
}
}
}