1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\admin\controller\cms;
- use app\common\controller\Backend;
- use think\Exception;
- /**
- * 内容模型表
- *
- * @icon fa fa-th
- */
- class Modelx extends Backend
- {
- /**
- * Model模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\cms\Modelx;
- }
- /**
- * 复制模型
- */
- public function duplicate($ids = "")
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $table = $this->request->request("table");
- try {
- $data = [
- 'name' => $row->getData('name') . '_copy',
- 'table' => $table,
- 'fields' => $row->fields,
- 'channeltpl' => $row->channeltpl,
- 'listtpl' => $row->listtpl,
- 'showtpl' => $row->showtpl,
- 'setting' => $row->setting,
- ];
- $modelx = \app\admin\model\cms\Modelx::create($data, true);
- $fieldsList = \app\admin\model\cms\Fields::where('source', 'model')->where('source_id', $row['id'])->select();
- foreach ($fieldsList as $index => $item) {
- $data = $item->toArray();
- $data['source_id'] = $modelx->id;
- unset($data['id'], $data['createtime'], $data['updatetime']);
- \app\admin\model\cms\Fields::create($data, true);
- }
- } catch (Exception $e) {
- $this->error("复制失败,错误:" . $e->getMessage());
- }
- $this->success();
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- }
|