How to create your own api with ACL in Magento
2010-03-12 11:18
716 查看
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.
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.
相关文章推荐
- 转:How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?
- How to create your own custom 404 error page and handle redirect in SharePoint
- How to create your own ListBox in C#
- How to create your own home SVN repository with Xampp/Apache
- How to create own operator with python in mxnet?
- How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?
- How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏
- How to create a DLL library in C and then use it with C#
- How to Write Your Own Linux Kernel Module with a Simple Example
- HOWTO: How to Provide Your Own DllMain in an MFC Regular DLL
- HOWTO INSTALL OWNCLOUD WITH NGINX IN UBUNTU LTS
- How to create custom navigation menu in SharePoint with XML data source 使用XML数据源在SharePoint创建自定义导航菜单
- Beyond REST: How to build a HATEOAS API in Java with Spring MVC, Jersey (JAX-RS) and VRaptor
- How to Set Up Your Own Home Seedbox (in Windows)
- DIY BROADCAST : How to build your own Internet TV Channel with Open-Source & other goodies
- How to create custom price in Magento?
- How To Write Your Own Ebook(r) In 7 Days!
- How To Create Your Own Smarty Function
- unity kinect2 怎么使用姿势或者使用你自己的How to Use Gestures or Create Your Own Ones
- How To Create Your Own Personal Document Viewer (Like Scribd or Google Books)