0

有没有办法覆盖位于的控制器文件/concrete/blocks/page_list/controller.php并将其放置在里面/packages/mypackage/blocks/page_list/?我想对原始编辑和视图进行一些更改。

/packages/mypackage/blocks/page_list/controller.php,我尝试这样做,但它似乎没有任何效果:

class PageListBlockController extends Concrete5_Controller_Block_PageList { ... }

4

2 回答 2

3

You can now override/extend core classes via packages in newer versions Concrete5 (v.5.6+).

You must add to your package's main controller.php file:

public function on_start(){
    $objEnv = Environment::get();
    $objEnv->overrideCoreByPackage('blocks/page_list/controller.php', $this);
}

You don't have to copy over the whole core controller, just declare your new block controller like this:

class PageList extends Concrete5_Controller_Block_Page_List {
    public function mymethod() {
    }
}

(what class you're extending and where you put the file may vary depending on your C5 version - just compare the /concrete/ folder structure and files for reference)

The following C5 forum posts may be of help:

Overriding Core Class with Package

Can A Package Override A Core Library?

A caution, though - if you're hoping to submit to the official C5 marketplace, they generally don't accept Add-Ons with overrides.

于 2013-10-08T20:18:35.600 回答
1

不可以。您不能从包中覆盖块控制器。想象一下,如果不止一个包这样做。(但是,您可以在包目录中拥有一个块模板,但这很有意义,因为它是添加而不是替换。)

如果可以的话,你应该把它放在/blocks/page_list/controller.php.

但是,如果您仍然需要从您的包中覆盖它,您应该查看不是很好支持Environment::overrideCoreByPackage()并尝试:

Environment::get()->overrideCoreByPackage('/blocks/page_list/controller.php', $myPackage);

见源码: https ://github.com/concrete5/concrete5/blob/master/web/concrete/core/libraries/environment.php#L123

以及使用示例:http: //www.concrete5.org/community/forums/customizing_c5/override-a-core-class-within-a-package/#460765

于 2013-08-18T14:25:36.640 回答