Ajax调用magento中的php脚本

时间:2012-12-05 14:44:06

标签: magento-1.7 magento

我创建了一个可在admin中访问的模块。在该模块中,我在.phtml(模板)文件中创建了一个表单,并在通过javascript验证后,我想将值保存在products表的数据库中。我搜索了很多,但我无法打电话给脚本!请指导我如何将调用发送到php脚本并成功获取数据,我必须创建哪些模块,控制器等?这是我的模块结构正在进行ajax调用,

code-> local-> myspace-> mymodule->(模型,控制器等,助手)我已经在adminhtml-> default-> default->模板中包含了模板文件。

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>

1 个答案:

答案 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