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