简体   繁体   English

joomla com_users控制器覆盖

[英]joomla com_users controller overriding

I can't override the controller of com_users (Joomla 3.4). 我无法覆盖com_users (Joomla 3.4)的控制器。 (I want, if a manager can make user registration on the site after when he loged in.So I want to see the registration form, if I loged in the site.) (我想,如果管理员在登录后可以在网站上进行用户注册,那么如果我登录了网站,那么我想查看注册表格。)

If I modify the original file, then it works fine, but I don't want to modify the original file. 如果我修改原始文件,则可以正常工作,但是我不想修改原始文件。 I tried 2 override plugins for this ( MVC override , Override master). 我为此尝试了2个替代插件( MVC替代 ,替代母版)。 These plugins override the file, but after I click the registration button I get the following error message: 这些插件将覆盖文件,但是在单击注册按钮后,我收到以下错误消息:

Fatal error: Cannot redeclare class UsersController in D:\\wamp\\www\\mysite\\components\\com_users\\controller.php on line 136 致命错误:无法在第136行的D:\\ wamp \\ www \\ mysite \\ components \\ com_users \\ controller.php中重新声明类UsersController

It's the same file. 这是同一个文件。 I modified the line class UsersController extends JControllerLegacy to this class UsersController extends UsersControllerDefault . 我将class UsersController extends JControllerLegacy为此类class UsersController extends UsersControllerDefault Because I read this here . 因为我在这里读过这个。 What is the difference? 有什么区别? Why doesn't it work this way? 为什么它不能这样工作? :/ :/

  1. If you have the MVC override plugin installed be sure to have "Make Extendable" set to yes in the backend (Plugins: System - MVC Override) 如果您安装了MVC覆盖插件, "Make Extendable"在后端将"Make Extendable"设置为“ ”(插件:系统-MVC覆盖)
  2. I advice you to put all overrides (html, code, etc.) in your template directory, so create the controller file as: templates/YOUR_TEMPLATE/code/com_users/controller.php 我建议您将所有替代项(html,代码等)放入模板目录,因此,将控制器文件创建为: templates/YOUR_TEMPLATE/code/com_users/controller.php
  3. Finally, in THIS controller file you override it like it was mentioned: 最后,在THIS控制器文件中,您将其覆盖,就像上面提到的那样:
    class UsersController extends UsersControllerDefault {

This should do the trick. 这应该可以解决问题。

This happened to me also. 这也发生在我身上。 The issue was the that I was also overriding a subcontroller (inside controllers folders) 问题是我还覆盖了一个子控制器(在controllers文件夹内)

I had to add 我必须添加

$bufferContent = str_replace('extends UsersController','extends UsersControllerDefault',$bufferContent);
$bufferContent = str_replace('require_once', '//require_once', $bufferContent);

after

$bufferContent = str_replace($originalClass,$replaceClass,$bufferFile);

This is a hack and will only work the com_user override. 这是一个hack,仅适用于com_user覆盖。 You need to change the first line to reflect your correct component class. 您需要更改第一行以反映正确的组件类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM