ecmall开发记录(三)
上回只是做出了一個菜單,實現不了功能有啥用,于是接著來,他不是說Missing controller嗎,我就給他添加一個controller。在app文件夾下復制friend.app.php重命名為account.app.php,直接走你,又出岔子了
缺少一個'AccountApp'類,這個類又是從何而來,誰要調用呢?
其實在index.php中就靜態調用了ECMall的方法startup()
/* 啟動ECMall */ ECMall::startup(array('default_app' => 'default','default_act' => 'index','app_root' => ROOT_PATH . '/app','external_libs' => array(ROOT_PATH . '/includes/global.lib.php',ROOT_PATH . '/includes/libraries/time.lib.php',ROOT_PATH . '/includes/ecapp.base.php',ROOT_PATH . '/includes/plugin.base.php',ROOT_PATH . '/app/frontend.base.php',ROOT_PATH . '/includes/subdomain.inc.php',), ));
定義到startup方法,在/eccore文件夾中找到了ecmall.php,注釋為“?ECMall框架核心文件,包含最基礎的類與函數”
View Code class ECMall {/* 啟動 */function startup($config = array()){/* 加載初始化文件 */require(ROOT_PATH . '/eccore/controller/app.base.php'); //基礎控制器類require(ROOT_PATH . '/eccore/model/model.base.php'); //模型基礎類if (!empty($config['external_libs'])){foreach ($config['external_libs'] as $lib){require($lib);}}/* 數據過濾 */if (!get_magic_quotes_gpc()){$_GET = addslashes_deep($_GET);$_POST = addslashes_deep($_POST);$_COOKIE= addslashes_deep($_COOKIE);}/* 請求轉發 */$default_app = $config['default_app'] ? $config['default_app'] : 'default';$default_act = $config['default_act'] ? $config['default_act'] : 'index';$app = isset($_REQUEST['app']) ? preg_replace('/(\W+)/', '', $_REQUEST['app']) : $default_app;$act = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : $default_act;$app_file = $config['app_root'] . "/{$app}.app.php";if (!is_file($app_file)){exit('Missing controller');}require($app_file);define('APP', $app);define('ACT', $act);$app_class_name = ucfirst($app) . 'App';/* 實例化控制器 */$app = new $app_class_name();c($app);$app->do_action($act); //轉發至對應的Action$app->destruct();} }可以看到這個方法取到了get過來的app和act,然后定義一個類名為$app_class_name = ucfirst($app) . 'App';
由此可知AccountApp就是get過來的app=account把首字母大寫后再加上'App'形成的類名。然后實例化這個類,然后調用這個實例的do_action()方法,再深入的我就不看了,
直接把account.app.php的第三行改為class AccountApp extends MemberbaseApp,錯誤消失。顯示為如下。
因為整個app都是復制的friend.app.php所以當前位置啥的也都顯示為friend_list,接下來再改這些當前位置和三級菜單
在account.app.php的index方法中把
/* 當前位置 */$this->_curlocal(LANG::get('member_center'), 'index.php?app=member',LANG::get('friend'), 'index.php?app=friend',LANG::get('friend_list'));/* 當前所處子菜單 */$this->_curmenu('friend_list');/* 當前用戶中心菜單 */$this->_curitem('friend');
?
改為
/* 當前位置 */$this->_curlocal(LANG::get('member_center'), 'index.php?app=member',LANG::get('account'));/* 當前所處子菜單 */$this->_curmenu('account');/* 當前用戶中心菜單 */$this->_curitem('account');
在第138行有一個創建三級菜單的方法_get_member_submenu()
改為
/*** 三級菜單** @author Hyber* @return void*/function _get_member_submenu(){return array(array('name' => 'account','url' => 'index.php?app=account',),);}
打完收工,就成了這個樣子
add_friend是怎么搞上去的呢,而且一點擊還是出現添加好友的窗口,我要的是添加充值信息的啊,這個應該是在模板里設置的吧。找找index()方法里的display,發現
$this->display('friend.index.html');
說明這個方法還是用了friend.index.html這個模板,咱們也不能隨便把人家的模板給改了,于是二話不說,復制\themes\mall\default文件夾下的friend.index.html,改名為account.index.html,順便把friend.form.html復制改名為account.form.html然后把上面那句話改為
$this->display('account.index.html');打開account.index.html,找到第7行,這就是添加好友按鈕的代碼了
<div class="eject_btn" title="{$lang.add_friend}"><b class="ico3" ectype="dialog" dialog_id="friend_add" dialog_title="{$lang.add_friend}" uri="index.php?app=friend&act=add" dialog_width="400">{$lang.add_friend}</b></div>
啥都別管,直接把這段里所有的friend替換成account保存,再把account.form.html里面所有的friend替換成account保存,刷新。
于是有了add_account按鈕了,我點
為什么彈出來的還是add_friend對話框呢?
再看上面那段按鈕的代碼,它的uri改成了uri="index.php?app=account&act=add",來到account.app.php,發現了問題所在,原來在這個app的add()方法里,調用的模板還是friend.form.html.那就把它改成
$this->display('account.form.html');
再刷新,就看到了
接下來還是中文的問題了,還是在\languages\sc-utf-8\common.lang.php文件下添加鍵值對嗎?No,ecmall為每個app都有一個相應的*.lang.php。既然這樣,我也來新建一個account.lang.php。具體代碼如下。
<?php return array( 'add_account'=>'賬戶充值', 'receiver'=>'充值金額', 'add_message'=>'充值留言' ); ?>
?
當然這都是先模擬實現,誰也不會用'receiver'當作充值金額,而且一定要注意保存時的編碼選擇,否則會出現亂碼,我這里使用UTF-8編碼保存,刷新。
OK!下一步就是提交數據了。
?
轉載于:https://www.cnblogs.com/wenshenliu/archive/2012/12/30/2839122.html
總結
以上是生活随笔為你收集整理的ecmall开发记录(三)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android edittext 限制文
- 下一篇: 分享30个激励的非营利网站设计精美案例