最近碰到了一个问题,网上有不少cakephp的plugin是自带模板文件的,文件比如 Plugin/Users/View/Users/login.ctp, 我想改写login.ctp但是这个plugin是一个git的submodule. 改了以后不能用submodule在别的机器上sync代码了.我查了一下 View的源代码,实现了下面的解决方案
1. 创建 app/View/Users/login.ctp
2. 创建 app/View/AppVIew.php
<?php
App::uses('View', 'View');
class AppView extends View {
protected function _paths($plugin = null, $cached = true) {
return array_unique(array_merge(
App::path('View'),
parent::_paths($plugin, $cached)
));
}
}
class AppController extends Controller {
public $viewClass = 'App';
}
搞定,现在可以在app/View下自由改写Plugin里的模板了.