【小(xiǎo)編推薦】Magento後台模塊示例(1)

2018-10-02   "←;|   ↑★&φ發布者:   | δ±→  查看(kàn):3320次

php

Magento的(de)後台的(de)模塊開(kāi)發相(xiàng)®&÷對(duì)于Magento的(de)前台模塊開(kāi)發 ®Ω而言,要(yào)複雜(zá)一(yī)些(xiē),這(zhè≤ε)裡(lǐ),說(shuō)下(xià)這(zhè)次示例的(de)M↓§πβagento後台模塊要(yào)實現(xiàn♠→)的(de)功能(néng),其實很(hěn)簡單,就(jiù)是(♣ ​™shì)前台有(yǒu)個(gè)表單提交數(shù)據,然後在後¶¥§台展示提交的(de)數(shù)據,實現(xiàn)前後台的(de)一(☆☆yī)個(gè)交互。
首先來(lái)做(zuò)一(yī)些(xiē)準備工(★✔<gōng)作(zuò):
1.安裝好(hǎo)Magento
2.使用(yòng)mysql工(gōng≥®‍σ)具
3.打開(kāi)Symlinks:

System > Configuratio≠​∑n > Developer ♥♦ ;> Template •↑♣λSettings,設置為(wèi)Yes.

4.關掉緩存:

System > Caλ•che Management&nΩ₽★bsp;> Select All&<₹≤±nbsp;> Disable&nbs₹α↓p;> Submit,點擊Flush&'₹nbsp;Magento Cache.

5.打開(kāi)錯(cuò)誤報(bào)告:
找到(dào) index.php 取消下(xià)面這(zhè)行€±(xíng)的(de)注釋:

ini_set('display_errors',&n>∏÷bsp;1);

然後将下(xià)面代碼:

if (isset($_SERVER[₽¶↓φ9;MAGE_IS_DEVELOPER_MODE&φδ±Ω#39;])) {
Mage::s'"✔etIsDeveloperMode(true);₩​
}

修改為(wèi):

//if (isset($_SERVER['MAGE_I÷σS_DEVELOPER_MODE'])) {
Mage::€♠♥setIsDeveloperMode(tr♦σ  ue);
//}

6.打開(kāi)錯(cuò)誤日(rì)志(zh♣φì):

System > Configura §↕tion > Develo€‍per,選擇 Log Settings,設置為(wè♥>i)Enabled.

7.修改seesion過期時(shí)間(&‌jiān),
對(duì)于開(kāi)發人(rén)員(yuán)來(l÷ε‍∏ái)說(shuō),免于不(bù)停的(de)登↔★♠​錄麻煩:(magento默認是(shì)15分(fēΩ‍→n)鐘(zhōng))

System > Configurati$§on->System > Adv ↓&λanced > Admin,選擇Secu¶ rity,默認是(shì)900seconds,

開(kāi)發過程中,設置為(wèi)86400seconds( ®24小(xiǎo)時(shí))。
此外(wài),你(nǐ)還(hái)需要(yào)設置php.ini的(de±≤≈)maxlifetime session expirat∑♣₽ion time,修改如(rú)下(xià):×♣

session.gc_maxlifetime&nbs<£p;86400

8.可(kě)以為(wèi)magento在虛拟機(jī)創建一(yī→∏÷)個(gè)快(kuài)照(zhào),利γα±于備份和(hé)還(hái)原
9.先創建一(yī)個(gè)前台模塊
對(duì)于前台模塊如(rú)何創建,Magento的(de)執★​行(xíng)流程是(shì)怎樣的(de)λ↑¶¥,這(zhè)裡(lǐ)就(jiù)不(bù)再累述,直接貼代碼:←←₽↔
創建目錄結構

app |-code
 |-----local
&n←♣&€bsp;|----------Message
♥♣₩
 |--------------Count
 |---↑§‍•---------------Block
 &n∞αbsp;   & βnbsp;  &nbΩ★♥sp;     &nbsΩ∞λ←p;   &↓φnbsp;  |---Adminhtml
&n•✘₩↔bsp;|------------------contro≥₽±"llers
   &≠βnbsp;    &nbs ♥★p;    ♦©α   &nbsΩ≥p;   &nbs✘​ππp;|---Adminhtml
&nbφ"sp;|------------------etc
&nbs€≈∞πp;    &''☆↕nbsp;  &nb☆±×•sp;     &n∑€Ω♦bsp;   &•"€nbsp;  |----config.xml
₩∞•₽
 |---------------♠×‍€---Helper
 |---------ε←---------Model

跟前台模塊不(bù)同的(de)是(shì),在Block和(hé)co€£ntrollers下(xià)分(fēn)别多(duō≠§≈ )了(le)Adminhtml文(wén)件(jiàn)夾。
首先還(hái)是(shì),需要(yào)mage&↑nto加載模塊,Message_Count.xml
etc/modules/Message_Count.x₹≥§ml

<?xml version=&qu÷≤β≤ot;1.0"?><config​©>
   &nb↕♣γsp;<modules>
   &φ☆nbsp;    •¥↑↑;<Message_Count>
&nbs&♥↔p;    &₩♥nbsp;     &nb★φ®sp;<version>0.1.0</version>$♣ε♣
     &↔∏nbsp;  </Messag≥→e_Count>
   &nb'₩sp;</modules>
  &nb‌✔¥ sp; <frontend><!-$ α<-這(zhè)裡(lǐ)是(shì)前台部分≠β(fēn)-->
    &n£ ∑bsp;   <routers®♣±∞>
    &n÷↔λΩbsp;   &n♥σbsp;   ™£';<count>
  &nbs→↓×p;    &π↓®nbsp;     &σ™★•nbsp;  <use>standard&l↓♦φφt;/use>
   &¶♠♥≤nbsp;     &nb  Ω≈sp;   ≈$♦;   <>σargs>
   &n&₹♣'bsp;    &nbs≈÷p;    &πφnbsp;    &nbs≈₩'p; <module>Message_Count<☆←♦$;/module>
 &↕←♠nbsp;    λ<<♦    &±​;     &nbε≠​ sp;    <froπ≠ε☆ntName>count</fr→¥ontName>
 &Ωβnbsp;     &nbs∑♦₩p;    &nπα¥♣bsp;   </↓> args>
    &n"Ω→bsp;     &nb×α>↓sp; </count>
  &n↑§≠bsp;   &‌¶®εnbsp; </route÷☆®÷rs>
   &nbs‌≠&p;    &≈&♦lt;layout>
 &δ™nbsp;   &nλλ₩bsp;   ÷ ;   <updates>
&n✔§"bsp;    ₩↕     &nbs★€p;     <♥>;count>
 &nbs≠¶←p;   &nb♦≈γsp;   ≥"​';   &nb™™ sp;    &nε←bsp;  <file>± ♣count.xml</file>
 &σ¥☆nbsp;    &n'€•÷bsp;   &↔ βnbsp;   'φ ₩  </couπ↔∞βnt>
    σ♥;     &nbs¶₩Ωp;  </upda↕©tes>
  ♠↓   &nb₩∞✘​sp;  </layout>
&£ε nbsp;   </fro∞​&​ntend><!--這(zhè)裡(lǐ)是(s¥≈hì)後台部分(fēn)-->
 &≤σnbsp;  <admin>
 ∞₹δ®;    &n•βbsp;  <routers>
&n•↔bsp;     &nbs→₩p;     <π✘↑Ω;count>
   &nb∞✘←¶sp;     ✘β<‍   &nbs→↓σ≈p;   <use>admi≈Ω©φn</use>
 &nb✔♥sp;   &nb<♥¥sp;     ☆∑÷≠   &n✘​bsp; <args>
 ↑<↑;     &nbs§‌p;   &n£σγβbsp;     ‍β↑;    &"♠±‍lt;module>Message_Count</mod¥&ule>
    &n→←↑•bsp;    &nb  sp;   &β✔∞nbsp;   &nb•Ωπ©sp;  <frontName>co ♠unt</frontName>
  ↕←£   &nbλ‌sp;    δ ;   &nb" >sp;  </args>
☆♥•    &nb₹≥sp;   &nb☆<≈sp;   </c✔∏★ount>
   &nb®'→±sp;    <∑↔";/routers>
  Ω↕εγ;  </ad₽‌≈♥min>
   &nbs £$≈p;<adminhtml>
  ♠¶     &nb₽×sp; <menu>
&nb↓Ω≤sp;     &★λ"nbsp;   &nb→↑©¶sp; <catalog>
 ★∞    &" >nbsp;   σ£     &≥¥nbsp; <children&g δ×♥t;
   &n★×bsp;   &nbsεε☆§p;     &nb←​✔sp;   &n≠±π€bsp;  <Count t≥ Ωranslate="title" modu€♠✔le="count">
&n'↓bsp;    &★δ nbsp;   &n•↔∏bsp;  &nbs​≠®p;     &nb$↑↑↑sp;    & וnbsp;<title>Count</♦‍₹title>
   ←₽σ;   & ∞☆±nbsp;     &nbs ‍≥✘p;   &nbs™'p;    &nbs<<&p;  <sort_order>1"Ω80</sort_order>
  &nbs₹ p;     ↔"    &♦®©βnbsp;   ₩>•     &n σ¶bsp;  <actio©∑₩σn>count/adminhtml_count&¶↕♠lt;/action>
 &nγ∑ bsp;     &nb☆±§♥sp;    &φ∏←↑nbsp;   ¥ε₹;    γ♥©↔;</Count>
  ∞♣₩      φ↔÷♥;     &nbs‌₹<€p;  </children&γσ gt;
     δ¥;   &nbs₹σφ p;   </catalog>×>;
    &nbs>☆p;   </menu>
&n♠¶§↑bsp;     ♦ ←;  <acl>&l¥Ω​t;!--這(zhè)裡(lǐ)是(shì)權限-->
& >nbsp;    &nb×φsp;     ♦≈φ€; <resources>
&n₹×bsp;     &n‍∑bsp;   &↔↕nbsp;     &l ≤t;all>
   &nbs$•₹p;    &♦$σ‌nbsp;  &nbs₽↓•p;     ε‍☆   <ε♦©title>Allow ₹☆Everything</title>←®;
   •↓♣   &n₹§<bsp;     &>εnbsp;   </a" ₽ll>
     ≤☆∞    £↕     &n→>≠bsp; <admin>
&nb©♦♥sp;     &δ≥♦≠nbsp;     &nbs" ↓✔p;      φ↔≤∑; <children>
 &×↔↕nbsp;     &δ₩γ↕nbsp;    &nb£≤'sp;    &nb '≤±sp;    &nbs ®>p; <Message_Count>
&nb↓ σsp;     &nbs≠¥≤>p;   δ ©    &nbsπ‍£p;     &nb§÷±sp;   '";    &nbλ< sp;<title>count Module&✔γ↓lt;/title>
   &nbs∞≠p;     &$‌nbsp;   &nb‍πsp;   &nbs₹β "p;    &γ‌​nbsp;    ÷™γ <sort_order>10</sort_ordα ↕er>
  &nb  ♥sp;    &n™δbsp;     &nε↑‍>bsp;    &nbs∞≈≤p;    ∏✘'✔; </Message_Cou∏‌nt>
     &>®§nbsp;   &nb÷ sp;    &nbs¥♦p;    &nbα♥ sp;</children>
×π
    ₽ σ$;   &nbs$'p;    &nbsφ•βp;   </admin↕÷>
  &nb♠£☆sp;      ₽₹;   </resources><≠Ω 
    &↕☆nbsp;   </ac‌® 'l>
     →$♥;   <layout₽→>
   &nb‍₹≈sp;   &nbs✘ε €p;   ∏↓ <updates>
  φ ¶     & ↕‌™nbsp;   &nbs©₽×p;    <count>Ω÷γ;
   & →φ♥nbsp;    &☆<γ♣nbsp;     &nbs∞→Ωp;    → ; <file>count.xml<£★;/file>
  £ε₽±;   &nbs★↔p;    &nb←€→sp;   &nbε​₹sp; </count>
&nb∑Ωσsp;   φΩ≈     φα↑•   </≈←updates>
   "Ω'♦    &₩₹✘πnbsp;</layout>
  &n≠↔ ≤bsp; </adminhtml> &nbs"¥​p; 
   ↑π <global>
  &nbש ‍sp;     ∏÷αλ<models><!--創建Model-->
±×≠→     &nbsΩ p;      &↓•¶∞lt;count>
 &nb↓γ×sp;   &n ♠‍bsp;     ¶§✘;    β®∞; <class>Message_Counλπ₩←t_Model</class>
  &nbγ≤±>sp;   &↑<nbsp;     &€↓± nbsp;   <res♠ ourceModel>count_mysql4</resour$γ₽☆ceModel>
 &n☆‌λbsp;     &nbΩ αsp;    &lΩ→₽t;/count>
 ✔₽∞    &nb™₽₩sp;    &nbs•β ¥p; <count_mysql4>
 &nb≤♥sp;    &n¥ bsp;      ≠±β;   <class>Me¥€ssage_Count_Model_Mysql4</class& ±€✔gt;
    &≈≤✘nbsp;   ¶™♦¥     €↑   <entities>
&n¶↓÷☆bsp;     &nbs₩αp;    ≥₹      &☆↓nbsp;  <cou¥♦↔÷nt>
  ÷£×₹    &↕Ω♦   &n✔♣↑←bsp;   ∞♠÷ε    ±Ω©¥    &•α→≈nbsp;  <table&g∏&≈t;count</table>
 &nφ≥bsp;     &nb™λsp;   &nbsδ✘Ωp;      ≠α  </count♣¥↓>
    &nb☆σ$sp;   &n≈©<bsp;   ♥α;    </en¥★tities>
  &σ♦nbsp;    &$πnbsp;    &δ₽lt;/count_mysql4>
§♠
     ←'α   </models>
&nbsε​βp;     &nb♠₩Ωsp; <resources>
∏↓‌φ     &nb✘≈≤↓sp;    ↔♣>•;  <cou•↓nt_setup>
  ¥↑;   &σ ε✔nbsp;   ‌↓;    &nbsΩ©★p;  <setup>
&n∑ ‌'bsp;  &nbsεδ£p;      ↔π;     $↓π;     <mod↑γule>Message_Count</module&•×<gt;
    €♠      &n↕&>∑bsp;  &nbs>≈p;   </setΩ≈≈§up>
  & ‌nbsp;     &nbs"φ∞p;     &nb∑∑‌©sp; <connect"'Ωσion>
   ©λ      §€↔↔;     &n✔₹∑™bsp;    &nbs"✔p;<use>core_setup</use>
​↔×     &₩£<λnbsp;    €βπ;   &nb ≥☆sp;  </connectio® →↕n>
     &☆$φnbsp;  &nb♣♠&±sp;   </ γcount_setup>
   &nbs✔ ‌p;     δ<™;   &♣£∞lt;count_write>
&nbσ✘φsp;     &nbsα♣±p;     &επ↕nbsp;   ‌•≤ <connection>
&nbs€™​δp;      λ≠;   &₹φ♦nbsp;    &₩✔nbsp;    &★σ→•lt;use>core_write</use>
&nb€♠" sp;     &n$☆×≈bsp;     &®∞≤nbsp;   ↓ε₩♥</connection>
  ↔✘$♦    &¶αnbsp;     <π∑ /count_write>
  &nbs δp;   &≥&∞σnbsp;     ±γ✔♣<count_read>
 &n♦↑​bsp;    ÷Ω<;     λπ    ♦​ <connection>
&n₽&¥>bsp;   &®"∑♦nbsp;     &n‌δ∞bsp;     &nb☆♦£✘sp;   <use>cor>€​ e_read</use>
  &n×&¶bsp;   &nbs∞₩p;   &n≠∏​‍bsp;     <¶&♦>;/connection>
 &≠'nbsp;   &nσ→bsp;   β★;   </count÷™♦_read>
    § ;   &nb✘±₽©sp;</resources>
 &nb"✔$‍sp;   &n‍♣♠bsp;  <blocks><!--¥☆創建Block-->
 &nbs ∏™★p;     &nbsΩ×γφp;    <count&∑←gt;
    &nb♥ γ>sp;    &↑‌✘nbsp;   "σ   &l​Ω☆↔t;class>Message_Count_Block</c•λlass>
  ±∑    &nbs£βp;    &<​nbsp;</count>
&​₩nbsp;     &σ<↓→nbsp; </blocks>
 &β>∏nbsp;   &n☆π∑bsp;  <helpers><→φ&!--創建helper-->
   ♥≤;    &nbελδ↓sp;   ≥✔✔ <count>
 &n§≈bsp;    Ω₩γ®   &nb≈÷÷sp;     &₽₩♥nbsp;<class>Message_Count_Hel≈ σ<per</class>
   ₹≈↔®;   &n©↑​®bsp;    ♥π </count>
&n£¥‍bsp;   &nbs☆≠p;   <✘®;/helpers>
   ♠↕£; </global></config>

現(xiàn)在來(lái)寫控制(zhì)器(qì)IndexContro ±ller.php

<?phpclass Message_£φ÷Count_IndexController ex &♣→tends Mage_Core_÷δ≈↔Controller_Front_Action{
&nb≈♥sp;   pu≈♣€₽blic function&nb'λsp;indexAction()
&n₩♣↕♣bsp;   {
&nbs& ☆p;      ♥∑; $this->loadL→≠ayout();
  &n ☆♦bsp;   &n✔✔§"bsp; $this->_initLayoutMessage☆•→®s('core/session');
"≥       &nb$"sp; $this->render≤₩ Layout();
  γφ   }
}

在控制(zhì)器(qì)IndexConγ☆©troller.php中,有(yǒu)$this->lo♣‌adLayout();$this->renderLayout();即需♥£×↔要(yào)加載模闆文(wén)件(jiàn)template下(x♠<∑ià)的(de)phtml文(wén)件(jià♠♣™n)。這(zhè)裡(lǐ)我們先來(lái)給數(s♠Ω×hù)據庫添加一(yī)張表,這(zhè)裡(l♣φǐ)使用(yòng)sql文(wén)件δ§(jiàn)件(jiàn):

sql |----count_setup
 ><®‌;     &n♠≥bsp;   |------πσ↓∏-mysql4-install-0.1.0.php

mysql4-install-0.1.0.php代碼如(rλ㮣ú)下(xià):

<?php
$installer = $th✔<≥₽is;
$installer->startSetup();₩≈₹✔
$installer->run(&qσ↓÷uot;
-- DROP ₩₹∞TABLE IF EXISTS&nb$​sp;{$this->getTable('cou♥£αnt')};CREATE TABLE&nb♣•sp;{$this->getTable('↓→≥count')} (`count_id` in≤‌±t(11) unsigned primary&nbΩ↓™sp;key auto_increment∑♥α not null,`Mode→αl_Name` varchar(200)™♥<λ not null,`Name` varc ₽₽har(250) not n∏&≤✔ull,`Serial_Number`&σ≥nbsp;varchar(100) not null✘φ> ,`Email` varchar(50) not  ✘¶;null,`Date_Purchased` date,`Me¥βδ≥ssages_Source`  var∏  char(30),`Content` varch★≤ar(300) not null) ENGIN×φ​E=InnoDB DEFAULT&•±' nbsp;CHARSET=utf8;
&q←✘•♣uot;);
$installer->endSetu₽✔p();

創建了(le)數(shù)據表,Magento需要€∞↑ (yào)與數(shù)據庫有(yǒu)CURD操‍↔♠作(zuò),就(jiù)必須會(huì)涉及到(dào)資₽☆源模型,所有(yǒu),接下(xià)來(lái),繼續"&δ來(lái)Model文(wén)件(jiàn)夾下(xià)來(lái)內≥₩≠(nèi)容:

Model |----Count.php
 | ♠----Mysql4
    &nb↑↕​sp;   |---Count.phα÷∞p
     &nbsπ∑ ÷p;  |----Count
​∞✘    ®$↔;    'γ≥ ;    &nb↕÷✘sp;  |----Collection. ★php

Model/Count.php

<?phpclass Message_Co§φ♣ unt_Model_Count  λ↕;extends Mage_Co'≥£←re_Model_Abstract{
 &n↑β<bsp;  public func×✔γtion _construct()
 &€<↑♣nbsp;  {
   •σ​;     &nb¶‌sp;parent::_construct();
&nb‌★₹¥sp;   &nbλ¥‌sp;   $this->_init( ε₹'count/count'±π★);
    }
}

Model/Mysql4/Count.ph•™p

<?phpclass Mess•φ∏∑age_Count_Model_Mysql4_Count ↑¶extends Mage_Core_Model_Mysql4_Abs ∑λtract{
  &nbs↓βp; public function&n₩×bsp;_construct()
 →¥;   { &↔ γ​nbsp;  
&nε→bsp;    &n$↕>§bsp;  // ® Note that the&≤εnbsp;count_id refers&nb← λsp;to the key&nb∑♥ ¥sp;field in your&nb♣ ©§sp;database table.
 →λ      &nbφ♦​sp;$this->_init('¶₩count/count',  ★;'count_id');
  ↓φ  }
}

Model/Mysql4/Count/Collectio♠γ©n.php

<?phpclass Message_Coun​✘t_Model_Mysql4_Count↕©_Collection extends Mage_Co≠"ε​re_Model_Mysql4_Collection_Abs♠₽tract{
    '​;public function♣± _construct()
 ∏♦φ   {
&nb≠±sp;   ¶§¥₽    ☆‍;parent::_construct();
∏↕€↕     ♦​   $this-&'♠gt;_init('count/count')£≤★™;
   &nbs‍φ±§p;}
}

到(dào)此為(wèi)止,Model就(jiù↕★)差不(bù)多(duō)寫完了(le)。但(dàn)是(shì)還(hái)★γ有(yǒu)很(hěn)多(duō)工(gōng)作(zuò↓ ‌$)要(yào)做(zuò),
Block和(hé)Helper的(de)內(nèi™♦)容要(yào)怎麽寫呢(ne)?
Helper/Data.php

<?phpclass Message_Coun"↓₩t_Helper_Data extends Mag≠→e_Core_Helper_Abstract{
}

Block/Count.php

<?phpclass Mess​♠‌£age_Count_Block_Count ¶ >&;extends Mage_Core_Block_Temp→σlate{
   >α×; 
}

現(xiàn)在隻剩下(xià),模闆phtml文(wén)件→↑ ∏(jiàn)和(hé)布局文(wén)件(jiàn) ☆♦₩layout下(xià)的(de)xml文>®<(wén)件(jiàn)了(le)。
design/frontend/rwd/default/layout/α&≤←count.xml

<?xml version="♥λ"∑;1.0"?><l★¥∑$ayout version="0.1.0&quδ↓ot;>
  &nbs®&$ p; <default>
™₩•★
    <∞•</default>
  λ¥® ;  <count_inde∏§<÷x_index>
   &nbsδ>¥p;    &l₽←t;reference nam∞ e="content">
 ₹™£    &n₩‌£​bsp;      ¶δ;<block type="count/cγ"ount" name=&q€<uot;count" templat®™≈δe="count/count.phtml&qu↔ ot; />
 ≥♥σ     "≠&   </referen<‍ce>
   ∞‍™; </count_index_ind€↑♥​ex>
  &nbs$↓p; <count_index_save>
&nb∏βsp;   &n ε ≤bsp;   < φ&★;reference name="content&φ quot;>
 &nbs♦∞✔ p;   &n&∞♥∏bsp;     &nbs→☆☆p;<block type="∏"✘$;count/count" name="₹↔≠↑count" temp¶£®late="count/save.phtml&quo©<φ♣t; />
  &nbsδ↔≥p;     &σ lt;/reference>
&n₽ ​§bsp;   &l ↕≈t;/count_index_save></la​♠'yout>

design/frontend/rwd/defaΩ↑σ✘ult/template/count/count.phtml&α™↓

<form id="c$Ωount" action=&q''☆uot;<?php echo¥±✔€ Mage::getUrl('co☆©σunt/index/save') ?>±​♣∏" method="✔€post" >
&n"★♦bsp;    &↕₩nbsp;  <fieldset>
♦✘™φ
     ♠∞;   &nbs©→$p;   &δ>★lt;ul>
   &nbs♦ p;     ≤‍≤✘;      β≥; <li>
 &n←φ$±bsp;    $≥↕      &σδnbsp;     &γ™λnbsp; <label><?php&n✔λ‌bsp;echo $this->_ ↕_('Model Nam>ε∑ e') ?></labe↔×→l>
   &nbs♥×p;    &nbs↕α≥↔p;    &n<♠bsp;  </li>
 'π∞>   &nbs↕​p;     &nbs©←←p;    &π‍≤nbsp;<li>
 &nb÷±‍sp;    &nbs→↕<p;     <σε    &↓™nbsp;   <i ←αnput type="text"&↓©®¶nbsp;id="Model_Name&σ≈←quot; name="Model↑≤♦_Name" class="≥↔→required-entry"/>​σ$;
   ↔✘<®      π₽★≠     γ<ε  </li>
 ₽π;     &n™☆bsp;      ♠©₩ ;   <li&gλ"t;
    &n♠÷≈≤bsp;     ®©♦&   &n∏×®<bsp;    ±←≥  <label><?php ₩★echo $this->__('Name&¶≈ #39;) ?></label>< ©σ/li>
  ★'σ&;   &♥↕<≈nbsp;     &nb£Ωsp;   &nbs♠₩♦p;<li>
  &n←"bsp;    ∏λ‍≥     &nbs↑"‌p;    &nbs→←≈p;  <inβ✘put type="tex<§¥t" id="Name&q​αφ↑uot; name="Name"&&₩nbsp;class="requ§↕¶ired-entry"/>
&n$'bsp;   Ω♦¥;      €₹β★      <××Ω↕;/li>
   &λ±↓ nbsp;    ≥>;      ∞∏§  <li>
'&∑Ω
      &✔‌​∑nbsp;   ™&α;      φ ≤;    <lab™×εel><?php echo $this-©♠σ™>__('Serial Number'♥₹±‍) ?></label>
 &n♥☆™bsp;    $λ₽;   &∑©nbsp;     ↑$↓✔ </li>
&nb®♥sp;     &n×±€bsp;    &nbs→​p;    <‌​←li>
   &nbs≠™p;      &π☆£nbsp;     Ω§↓;    <input¶δ± type="texε♣t" id="Se§​₽☆rial_Number"&nb÷↓>sp;name="Serial_Number"&nb₹&™sp;class="validate-number&nbsΩ&p;required-entry"/>
 ÷≈;    &nbs↕₹✔Ωp;    γ"‍;   &nb™₹♦€sp;  </li> ©φ';
   &n↑αbsp;     &nε bsp;   ↓δ≤   <li∑←₩>
    &n∏®bsp;     &nb←εsp;     &nbs±¶​₩p;   <label>≈  ¶<?php echo $thi♣σs->__('Email¶£✔9;) ?></label>
 α‌π≈;     &nbs'‌€p;   &±©nbsp;     & ​®↕lt;/li>
   &nbs€×♦p;    &nbδ♣sp;   &nb ★sp;   β✔÷★<li>
    &±☆nbsp;     &nb£βsp;     &nbs•₩p;   <input typ "e="text" Ωσ<id="Email" name=&q™' ✔uot;Email" cl©'©ass="required-entry valid £‌ate-email"/>
 &n₹→δbsp;   &nλφ ♣bsp;     δ£   &n✔ ∏bsp; </li>
&nbβ  £sp;     &n'→∑"bsp;     &nβ♣÷ bsp;   <&€ ;li>
     ×$€β   &nb≠♥sp;     &n↕↕•±bsp;    σα ; <label><?php ✔​<₩;echo $this->__('Da∏σ∏ta Purchased') ?></δ‌δlabel>
 &nbs &≠p;   &>λnbsp;  &nb‍εsp;      •↑<‌; </li>
   &>$€nbsp;    &★§ &nbsp;  &nbs✘↕€<p;    <liγ∏φφ>
    §​↕↔;      ¥∞×    &&™nbsp;     &lλ•☆t;input type="date"&n♣€₩'bsp;id="Data_Purchased&quo∑☆‍βt; name="Data∞€  _Purchased" class="valid‍πate-date" />
 ≠∏≈    &nδ ♣₽bsp;     &nbsβ<σ✔p;    </l♣σi>
   &nbγ§sp;    &π↕ nbsp;     ↓<®₽  <li>
  ∏​<σ     &nbs‌​p;     &n‌₹₹₹bsp;   ♦    <lab×"Ω©el for="Mes§× ♣sage_Source"><?php&nb♥"<sp;echo $this->__('How&n&↕♠±bsp;Did You Hear About→≈$✔ INGEAR?') ?&g¥>Ω§t;</label>
&nb≥₽♠sp;     &n•Ω&λbsp;   &n₩$£‌bsp;    ∑€$∑; </li>
 &∏δnbsp;  &nbs→★☆γp;    &nbα≈₽♦sp;   &nbsδ∏Ω★p;  <li>
&★∑>≥nbsp;     &nb‌σsp;     &n¶•£♦bsp;      ®✔  <select i≈→d="Messages_Source" na₽γ↓∑me="Messages_Source"&nbs×φδφp;class="validate-select&'♣Ω×quot;>
   &nb★€sp;   &nb  $sp;    >✘∏₽;      &↓≥nbsp;   &nb​"'sp; <option value=&qu←¶ ot;Web_search">Web se¶&arch</option>
₩α∞
     &n≠× ₹bsp;      ♠¶±;     ±₽≤      "σ→; <option value="On©&line_review">Online&nbs∏<p;review</option>
  < →♦       &↔®;    ±β↑    γ≈      &n☆εδ₹bsp;   <op•£₩©tion value="O€★±nline_Ad">Online Ad&∏£₹lt;/option>
   ≈←    &nb£≠Ωsp;    &nbε↕¥sp;     ♦÷      ≈δ★;<option value=&q$$uot;Other">Other&l'φt;/option>
   ♣•←‍    '$;     &n✔≈₽bsp;       ↔   </select>
 &✘♣nbsp;    ¥";   &n λbsp;     ✘γ•©; </li>
   &÷α<πnbsp;   &πφnbsp;    &n®"₩bsp;   <li>Ω'  
   &♣&​≈nbsp;     ∑≤;      &n™​φγbsp;   'β₹₩ <label><?php&nβ♠§bsp;echo $this->__(">'Let us know h✘✔&≈ow we\'re doing!Tel$≤Ω l us what y≥♥πou think about oδΩ♦≠ur products?') ?>&l€≠‌€t;/label>
  ™≤÷    &n ₹φ bsp;    ε      •✔</li>
 &nbs¥φ§‌p;   &nb≠© ↕sp;   ±♣•;     &nbΩ‍αδsp; <li>
 &↕€→ nbsp;   &n≤¶bsp;    &nbs£&p;    &nb ‍↓¥sp;   &¶ nbsp;<textarea&nbπ>λ±sp; rows="10&quo≠ ☆t; id="Conte♣∏×nt" name="↔≥₽‍;Content"><↕δ≤∏;/textarea>
  &nbs→ ∑p;    &nbπ₽sp;   &nb©φ&sp;    </©₹li>
   &nbsα p;   &n≤↑bsp;     &δΩ£>nbsp;  <li>
 &nb♥§∏↕sp;    &nbs↓ε>♥p;    ↕₩↓      &n‌ ‍✘bsp;  <input&nb$βsp;type="submit" value=∞"∑✔"<?php echo&nbs®>p;$this->__('sub')₩σ∏ ?>" />
&¶¶♣☆nbsp;     &nb©Ω♦sp;   ↑Ω≥♠    &→ ©βnbsp; </li>
 ☆₽;     ¶€÷     ↕♣‍; </ul>
λ♦€     ∑π;   </fieldse​≤∞t></form>

現(xiàn)在可(kě)以來(lái)看(kàn)看(€≠kàn)效果:
圖片描述
然後再在IndexController.php控制(zhì)器(q>≤ì)中添加模闆提交的(de)處理(lǐ)方法

public function≥≤∏  saveAction()
{    ✘★• $data = $this-&g↑≤★‌t;getRequest()->getPost$Ω←&();   ‌ ; $model = Mage::ge♦$‍tModel('count/count');&n≤↔bsp;  &nbs₹∏p;$result = $mode↔₽l->setData($data)->₽φ↕;save();    //$β↑>¶this->loadLayout();&nbs≠$★p;   //$this->re↓★nderLayout();   &←™φ $this->_redirect('*/*/&#♠$39;);
}

接下(xià)來(lái),要(yào)做(zuò)的(de)∏πβ✔就(jiù)是(shì)寫後台部分(fēn),實現(xσ iàn)表單提交,後台接收和(hé)展示。