简体   繁体   English

如何在cakephp 3中为插件添加View类?

[英]How to add a View class for a plugin in cakephp 3?

As the heading to this question states how does one go about adding/integration a View class to a plugin in Cakephp 3? 正如该问题的标题所述,如何在Cakephp 3中向插件添加/集成View类?

There is the AppView class for the application but when baking a plugin no View class is included. 该应用程序有AppView类,但是在烘焙插件时不包含View类。

There is no View class baked into plugin, because by default plugins are using View class from main application. 插件中没有View类,因为默认情况下,插件使用的是主应用程序中的View类。

If you need to do some specific view-rendering logic in your plugin, you can create eg. 如果您需要在插件中执行某些特定的视图渲染逻辑,则可以创建例如。 YourPluginDir/src/View/CustomView.php and do your things there. YourPluginDir/src/View/CustomView.php并在那里做您的事情。 You need also to tell your controller to use this View class: 您还需要告诉您的控制器使用此View类:

$this->viewBuilder()->setClassName('YourPlugin.Custom');

More info about custom View classes can be found in docs: Creating your own view classes in CakePHP 有关自定义View类的更多信息,请参见docs: 在CakePHP中创建自己的视图类

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

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