Tôi cần api còn lại để tạo ra khách hàng trong magneto cho rằng tôi đi theo hướng dẫn http://www.authenticdesign.co.uk/extending-magento-rest-api-v2/Tuỳ chỉnh REST API trong Magento
này Tôi đi theo nó từng bước, Nhưng Khi tôi kiểm tra các api về khách hàng còn lại nó cho tôi: {"messages":{"error":[{"code":404,"message":"Request does not match any route."}]}}
Tôi không biết mình đang phạm sai lầm ở đâu. Giúp tôi ở đây vì tôi rất mới với Magento cũng như cho php.
Các bước thực hiện:
1. Gia hạn Enabled tại (app/etc/module/Custom_Restapi.xml)
<config>
<modules>
<Custom_Restapi>
<active>true</active>
<codePool>local</codePool>
</Custom_Restapi_Groups>
</modules>
</config>
2. config.xml tại (app/code/local /Custom/Restapi/etc/config.xml)
<?xml version="1.0"?>
<config>
<modules>
<Custom_Restapi>
<version>0.1.0.0</version>
</Custom_Restapi>
</modules>
<global>
<models>
<restapi>
<class>Custom_Restapi_Model</class>
</restapi>
</models>
</global>
</config>
3. api2.xml tại (app/code/local/Tùy chỉnh/Restapi/etc/api2.xml)
<?xml version="1.0"?>
<config>
<api2>
<resource_groups>
<restapi translate="title" module="Custom_Restapi">
<title>Custom Rest API</title>
<sort_order>10</sort_order>
</restapi>
</resource_groups>
<resources>
<restapi translate="title" module="Custom_Restapi">
<group>restapi</group>
<model>restapi/api2_restapi</model>
<title>Testing My Rest API</title>
<sort_order>10</sort_order>
<privileges>
<admin>
<create>1</create>
</admin>
</privileges>
<attributes translate="" module="Custom_Restapi">
<firstname>First Name</firstname>
<lastname>Last Name</lastname>
<email>Email</email>
<password>Password</password>
</attributes>
<routes>
<route>
<route>/customer</route>
<action_type>collection</action_type>
</route>
</routes>
<versions>1</versions>
</restapi>
</resources>
</api2>
</config>
4. Mẫu Lớp Restapi.php tại (app/code/local/tùy chỉnh/Restapi/mẫu/Api2/Restapi.php)
<?php
class Custom_Restapi_Model_Api2_Restapi extends Mage_Api2_Model_Resource
{
}
?>
5. V1.php tại (app/code/local/Custom/Restapi/mẫu/Api2/Restapi/Nghỉ ngơi/Admin/V1.php)
<?php
class Custom_Restapi_Model_Api2_Restapi_Rest_Admin_V1 extends Custom_Restapi_Model_Api2_Restapi
{
/**
* Create a customer
* @return array
*/
public function _create() {
$requestData = $this->getRequest()->getBodyParams();
$firstName = $requestData['firstname'];
$lastName = $requestData['lastname'];
$email = $requestData['email'];
$password = $requestData['password'];
$customer = Mage::getModel("customer/customer");
$customer->setFirstname($firstName);
$customer->setLastname($lastName);
$customer->setEmail($email);
$customer->setPasswordHash(md5($password));
$customer->save();
return json_encode(array("testing","Success"));
}
}
?>
Và url của tôi giống như: baseurl/api/rest/customer
xin lỗi vì thẻ toàn cầu tôi sửa chữa ngày hôm qua bản thân nhưng không được cập nhật ở đây Nhưng tôi không nhận được điểm thứ 2 của bạn hoàn toàn bạn có thể elabrote hơn một chút (có tôi đang sử dụng url như www.myweb.com/api này/phần còn lại/khách hàng trong yêu cầu đăng bài) Cảm ơn – Spartan
để bạn không còn sử dụng url này nữa? Và url của tôi giống như: apiurl/customer/create –
Đối với điểm thứ hai, tôi đề nghị xem xét lớp Mage_Api2_Model_Router để xem nó thực sự chọn phương thức để gọi trong lớp mô hình của riêng bạn như thế nào. Nó dựa trên sự kết hợp của phương thức HTTP và loại dữ liệu nội dung. Đó cũng là nơi ngoại lệ cụ thể của bạn bị ném. –