在 CNIS (Canadian Network for International Surgery, 非營利組織) 當志工時推薦他們一個我比較熟悉的 Extjs framework, 但這個框架其實不好上手。同事問我怎麼從 db 撈一組國家列表, 前端用 Extjs 的 combobox 元件來互動 ? 於是我就動手了, 發現還真的挺複雜的, 所以趕快來記錄一下。 需求重點提示 這個下拉式選單 (combobox) 的內容是透過 ajax 初始化他的可用選項 獨立創建一個 controller.js 專門接收這個 request, 並與 MySQL 完成交互, 回傳 JSON 格式資料 需存取 stored-procedure combobox 需有一個 template 方便調整符合站台的樣式 (他們不要 Extjs 內建的樣式) 程式筆記 MySQL Store Procedure CREATE DEFINER=`my_db`@`%` PROCEDURE `my_sp`( ) BEGIN SELECT `country_code` AS `key`, `country_name` AS `name` FROM `myDB`.`myTable`; END$$ controller.php Yii framework 有個驗證機制, 需要 allow 給什麼 user 可存取什麼 controller, 要記得加上這一段代碼 (如下 accessRules 函式), 否則會得到 server side 的訊息: failed to load resource the server responded with a status of 403 (access forbidden) controller // authorize the access permission public function accessRules() { return array( ..., array('allow', 'actions'=>array('create...
劍心 ~紀念軟體開發 10+ 年~ ~紀念寶寶 元 年~