叶子的家

~●    ~●  ~●          ~●   ~●~●                           ○
    离成功还很远,距离长着叻,Fighting!
随笔 - 44, 文章 - 1, 评论 - 697, 阅读 - 22万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

How to create your own api with ACL in Magento

Posted on   绿叶  阅读(925)  评论(0编辑  收藏  举报

Finally, I got my customize api works with Magento today. I was confusing by the complex configuration xml files in magento, here I post my example which might be helpful though.

This example passed testing under Magento ver 1.3.2.4 using XML-RPC in .net platform.

 

Steps:

1. /app/etc/modules/Hanix_All.xml

复制代码
1 <?xml version="1.0"?>
2 <config>
3   <modules>
4     <Hanix_Customize>
5       <active>true</active>
6       <codePool>local</codePool>
7     </Hanix_Customize>
8   </modules>
9 </config>
复制代码

 

 

2. /app/code/local/Hanix/

 

3. /app/code/local/Hanix/Customize/etc/config.xml

复制代码
 1 <?xml version="1.0"?>
 2 <config>
 3 
 4   <modules>
 5     <Hanix_Customize>
 6       <version>0.1.0</version>
 7     </Hanix_Customize>
 8   </modules>
 9 
10   <global>
11 
12     <models>
13       <customize>
14         <class>Hanix_Customize_Model</class>
15       </customize>
16     </models>
17 
18   </global>
19 
20 </config>
复制代码

 

 

4. /app/code/local/Hanix/Customize/etc/api.xml

复制代码
 1 <?xml version="1.0"?>
 2 <config>
 3   <api>
 4     
 5     <resources>
 6       <customize_api translate="title" module="customize">
 7         
 8         <title>Customize Resource</title>
 9         <model>customize/api</model>
10         <acl>customize</acl>
11 
12         <methods>
13           <test translate="title" module="customize">
14             <title>Test Method</title>
15             <acl>customize/test</acl>
16           </test>
17         </methods>
18         
19       </customize_api>
20     </resources>
21 
22     <acl>
23       <resources>
24         <customize translate="title" module="customize">
25           <title>Customize APIs</title>
26           <sort_order>1</sort_order>
27           <test translate="title" module="customize">
28             <title>Test api</title>
29           </test>
30         </customize>
31       </resources>
32     </acl>
33 
34   </api>
35 </config>
复制代码

 

 

 

5. /app/code/local/Hanix/Customize/Model/Api.php

复制代码
1 <?php
2 
3 class Hanix_Customize_Model_Api extends Mage_Api_Model_Resource_Abstract
4 {
5     public function test()
6     {
7         return "hello test...";
8     }
9 }
复制代码

 

 

OK! that are the five steps what you need to be done. And don't forget to refresh the magento cache or just simply disable it. Now go to Magento backend: System/Web Service/Roles. Your api will be there.

 

Now, you can create an web service account to perform test. I used my own xml-rpc api showed below:

 

As can be seen, string "hello test..." returns correctly.

 

 

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示