以 CakePHP 開發 Mambo/Joomla 元件

edited 十月 2013 in CakePHP
下面這篇文章有個範例,展示了如何在 Mambo/Joomla 中透過 CakePHP 開發元件( component ),我把內容與檔案複製過來,也許有空時會試試 :)

http://forum.mambo-foundation.org/showthread.php?t=6701&page=2
As promised. The attachment is the cake blog component for Mambo.

1) All component files are in the com_cakeblog folder.

/com_cakeblog
/com_cakeblog/controllers
/com_cakeblog/models
/com_cakeblog/views
etc.

2) Once installed you need to edit the /com_cakeblog/config/database.php file to modify your database settings. This could easily be done using the post install php file for the component or getting the db settings from Mambo. I just didn't do it.

3) You need to have a copy of the cake framework in the /cake folder in the root of your Mambo install. By keeping the framework there, all components can access it. It could potentially be installed by the component's install file as well if it's not already there or have a separate component just to install the framework

4) None of the cake framework files in the root (/cake) require changes. In the component folder itself (com_cakeblog) I only modified the /webroot/index.php file to provide the appropriate location for the cake app folder, which is the component folder itself. These constants are the ones I changed: ROOT, APP_DIR, CAKE_CORE_INCLUDE_PATH

5) I added a new helper in com_cakeblog/views/helpers/htmlcms.php. It's an extension of the core html helper to create the right urls in Mambo when using the url and link methods. I neglected to include the Itemid, but this should be straightforward.

6) There's no admin interface, you need to create a new link url menu and point it to: index.php?option=com_cakeblog

The good thing about this approach is that everyone can simply use the same framework files and do whatever they want with their application (component) files.

For the url I am using the $_GET url parameter in the component and putting the same values that would be used with Cake standalone. So I have option=com_cakeblog&url=/post/view/1 instead of following the typical option=cakeblog&task=post&action=view&id=1... approach used in Mambo. This way there's no url translation requirement, it just works and one could have semi SEF urls right from the start if instead of using id=1 one used the blog title in the url segment.

Regarding the admin interface. I have read there are 2 approaches for this:

1) Use an admin controller in the same folder used for the component and restrict access to it through ACL checks

2) Use a separate application folder, which would be the typical administrator/components/com_cakeblog folder, but then you would have to duplicate models/views if you need to use some of the frontend ones. I think this is the best approach to separate both interfaces.

Enjoy and let me know if you can't get it working.

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=3126
Sign In or Register to comment.