2012-12-05 48 views
0

我創建了一個可在管理員中訪問的模塊。在該模塊中,我在.phtml(模板)文件中創建了一個表單,並在通過javascript驗證後,我想將這些值保存在產品表中的數據庫中。我搜查了很多,但我無法打電話給腳本!請指導我如何將呼叫發送到php腳本併成功獲取數據,我必須創建哪些模塊,控制器等來執行此操作?這裏是我的模塊結構,使阿賈克斯呼籲,Ajax調用magento中的php腳本

代碼 - >本地 - > myspace-> mymodule - >(模型,控制器等,助手),我已經包含模板文件在adminhtml->默認 - >默認 - >模板。

config.xml文件:

<?xml version="1.0"?> 

<config> 
    <modules> 
     <Inchoo_CoffeeFreak> 
      <version>0.1.0</version> 
     </Inchoo_CoffeeFreak> 
    </modules> 

    <global> 
     <blocks> 
      <coffefreakblock1> 
       <class>Inchoo_CoffeeFreak_Block</class> 
      </coffefreakblock1> 
      <coffefreakblock2> 
       <class>Inchoo_CoffeeFreak_Block_EditSpecial</class> 
      </coffefreakblock2> 
     </blocks> 
     <helpers> 
      <coffefreakhelper1> 
       <class>Inchoo_CoffeeFreak_Helper</class> 
      </coffefreakhelper1> 
     </helpers> 
    </global>  






    <admin> 
     <routers> 

      <samplerouter1> 
       <use>admin</use> 
       <args> 
        <module>Inchoo_CoffeeFreak_AdminControllersHere</module> 
        <frontName>admin</frontName> 

        <modules> 
         <sintax after="Inchoo_CoffeeFreak_AdminControllersHere">Mage_Adminhtml</sintax> 
        </modules> 
       </args> 
      </samplerouter1>   
     </routers>  
    </admin> 





    <adminhtml> 


     <menu> 
      <mymenu1 translate="title" module="coffefreakhelper1"> 
       <title>PrintInfo</title> 
       <sort_order>20</sort_order> 
       <children> 
       <!-- Note the misleading "module" attribute. 
        It actualy refers to one of the declared helpers --> 

        <myitem1 translate="title" module="coffefreakhelper1"> 
         <title>Add configuration</title> 
         <action>samplerouter1/FreakOut</action> 
         <sort_order>1</sort_order>       
        </myitem1> 

        <myitem2 translate="title" module="coffefreakhelper1"> 
         <title>Change configuration</title> 
         <action>samplerouter1/FreakOut2</action> 
         <sort_order>2</sort_order>       
        </myitem2>      


       </children> 
      </mymenu1> 
     </menu> 
    </adminhtml> 
</config> 
+0

您可以將您的代碼 –

+0

你的意思是代碼 - >本地的config.xml - > myspace-> mymodule-> etc-> config.xml? – MJQ

+0

您是否想添加或更新產品? –

回答

2

你應該能夠完成大部分的你的努力在產品管理中的事,但如果你想創建自己的自定義模塊,以節省產品數據,那麼你會需要做這樣的事情

應用程序/代碼/本地/ MySpace的/ mymodule中/控制器/ IndexController.php

<?php 
class Myspace_Mymodule_IndexController extends Mage_Core_Controller_Front_Action 
{ 
    public function SaveAction() 
    { 
     $product_id = Mage::app()->getRequest()->getParam('product_id') 
     $product = Mage::getModel('catalog/product')->load($product_id); 
     $product->setName('new_name'); 
     ..... 
     $product->save() 
    } 
} 

看看@http://www.phpzag.com/create-custom-module-with-custom-database-table/

在您的PHTML文件,你就必須按你的Ajax行動www.site.com/admin/mymodule/index/save

+0

問題是我必須從表單中獲取數據。所以要從HTML獲取數據,我需要提交表單並通過發佈或通過ajax請求獲取數據!然後我必須根據那個更新產品! – MJQ

+1

@ R.S。回答這部分的問題,你使用這段代碼:$ product_id =法師::應用程序() - > getRequest() - > getParam('your_param') – pzirkind

+0

在我的管理員,安全密鑰打開!所以我在螢火蟲中看到它將請求發送到儀表板,因爲它不識別密鑰!那我該怎麼做呢? – MJQ