Joomla 2.5 ―在组件的前端部分使用管理员组件控制器 [英] Joomla 2.5 ― using administrator components controllers in frontent part of component

查看:71
本文介绍了Joomla 2.5 ―在组件的前端部分使用管理员组件控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用在

处创建的控制器

how can I use the controllers created at

/administrator/components/com_mycom/controllers/*

/components/com_mycom/mycom.php

详细信息:

我有一个带有»add«方法的»log«控制器,我想从前端使用它.我未在后端登录,该任务未执行,并且出现500错误.所以只想在后端包括后端controllerpath,以便JController::getInstance( 'Mycom' )仍然有效.

I have a »log« controller with an »add« method, and I would like to use this from the frontend. I one is not logged in in the backend the task is not executed and a 500 error rises. So just would like to include the backend controllerpath in the frontend, so that JController::getInstance( 'Mycom' ) still works.

问候...

经过长时间的搜索,我发现了一个或多或少的未记录参数: JController::getInstance()方法,即第二个方法:$config = array().通过源代码,我发现有趣的»config-array«中有一个键,即:»base_path«.

After a long time of searching I could find a more or less undocumented Parameter of the: JController::getInstance() method, namely the second one: $config = array(). Going through the source code I found out that there is one key of the »config-array« that is of interest, which is: »base_path«.

呼叫:

JController:getInstance( 'Mycom, array('base_path' =>JPATH_ADMINISTRATOR.DS.'components'.DS.'com_mycom')' );

始终交付后端控制器,并且可以在前端安全地使用它们.但是,必须注意,然后还要从组件的后端获取视图.就我而言,我只是用它来进行ajax调用,所以没关系,但是在计划用»后端控制器«创建»前端视图«时,需要谨慎使用此方法.

always delivers the backend controller and one can use them safely in the frontend, BUT one must take care that then also the views are taken from the backend side of the component. In my case, I just use it to make ajax-calls so it does not matter, but one needs to be careful with using this method when planning to create »frontend views« with »backend controller«.

问候...

推荐答案

我最近遇到了一个类似的问题,我想在前端也使用整个CRUD系统表单的后端.

I had recently a similar problem where I wanted to use the whole CRUD system form back-end also in front-end.

这是对我有用的方法(我并不是说这是推荐的或最佳做法):

This is the method that worked for me (and I am not saying that this is recommended or best practice):

我刚刚从后端对文件夹/文件结构进行了建模. PHP文件包含以下内容:

I've just modeled the folders / file structure from backend. PHP files contained something like:

require_once JPATH_ADMINISTRATOR . '/components/com_mycom/controllers/log.php';

这篇关于Joomla 2.5 ―在组件的前端部分使用管理员组件控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆