如何将数据从正常的html表单发布到Magento Rest Api模块访客或管理员控制器功能



我创建了一个html表单,如下所示:-

<form action="http://localhost:81/magento/api/rest/forgetpass" method="post">
    <input type="text" name="apikey" placeholder="Api Key"/>
    <br/>
    <input type="text" name="email" placeholder="Email"/>
    <br/>
    <input type="submit" value="Submit"/>
</form>

此文件的位置为:-C:\examplep\htdocs\magento\api_files\testapi.php

现在我的客人控制器功能是:-

<?php
/**
 * Override for Magento's Catalog REST API
 */
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
class Esoft_ExtendRestApi_Model_Api2_Forgetpass_Rest_Guest_V1 extends Mage_Api2_Model_Resource {
    /**
     * Retrieve the attribute options
     * @return attribute options
     */
    
    protected function _update($data)
    {
        $email = $data["email"];
        try 
        {
            $customer = Mage::getModel('customer/customer')
                    ->setWebsiteId(1)
                    ->loadByEmail($email);
            $customer->getRpToken();
            $customer->sendPasswordResetConfirmationEmail();
            
            $array = array("status" => "200", "error" => "Email sent successfully.");
            return json_encode($array);    
        } catch (Exception $e) {
            $array = array("status" => "500", "error" => $e->getMessage());
            return json_encode($array);
        }      
    }
    
    protected function _retrieve() 
    {
        //code
    }
    /**
     * TODO
     *
     * @return int
     */
    protected function _retrieveCollection() 
    {
        //code
    }
}

现在我想做的是将数据从html表单传递给这个控制器函数。

我试图提交数据,但上面写着:-

<magento_api>
<messages>
<error>
<data_item>
<code>403</code>
<message>Access denied</message>
</data_item>
</error>
</messages>
</magento_api>

是否创建了api2.xml如果是,那么请按照以下步骤为您的模块分配角色:

system->web services->REST Role guest

之后找到您的模块并检查权限。

system->web services->REST Attribute guest

希望这将有助于

最新更新