Jill 筆記
:::
:::
所有書籍
「Xoops新物件寫法」目錄
MarkDown
3-1 新增到資料庫
1. 前置作業
1-1 流程
2. 列出所有活動
3. 新增活動表單
3-1 新增到資料庫
3-2 編輯活動表單
4. 刪除活動
5. 修改前台首頁
4. 刪除活動
Xoops新物件寫法 ========== 1. 讀出資料 [action/AdminAction.class.php](https://github.com/tnjaile/ck_signup/commit/b1303840741e52cbc64ade4a6b644efcdbd9186f#diff-0ece6698acedde7d0cebc5f0184eee02 "action/AdminAction.class.php") ```php if (isset($_GET['action_id'])) { $_OneAction = $this->_action->findOne(); $this->_tpl->assign('next_op', "update"); } else { $_OneAction['enable'] = 1; $this->_tpl->assign('next_op', "add"); } $this->_tpl->assign("OneAction", $_OneAction); ``` 2. 加入編輯 [action/AdminAction.class.php](https://github.com/tnjaile/ck_signup/commit/ff09b723746d394ff27b4c037b8c951bc72775aa#diff-0ece6698acedde7d0cebc5f0184eee02 "action/AdminAction.class.php") ```php if ($_POST['next_op'] == "update") { if ($this->_action->actions_update()) { $_message = "修改成功!"; } else { $_message = "修改失敗!"; } } ``` 3. model/ActionsModel.class.php ```php public function actions_update($_selectData = array()) { $_where = array("action_id='{$this->_R['action_id']}'"); if (!$this->_check->oneCheck($this, $_where)) { return; } if (!$this->_check->addCheck($this)) { return; } $_selectData = empty($_selectData) ? $this->_fields : $_selectData; $_updateData = $this->getRequest()->filter($_selectData); parent::update($_where, $_updateData); return $this->_R['action_id']; } ``` 4. 修改樣板 [templates/op\_actions\_form.tpl](https://github.com/tnjaile/ck_signup/commit/29231b28836c97a9b81e664c2892dc98356a8fda#diff-d369f31e3b6c321cd55704cc89c314fb "templates/op_actions_form.tpl") ```smarty
```