我需要将模块的视图作为局部视图加载到应用程序的另一个视图中.我在手册中找不到有关如何执行此操作的线索.
该视图完全独立于模块:
<?PHP
// This is the module's class. Do I need it here?
use vendor\xxx\cropk\CropK;
/* @var $this yii\web\View */
$this->title = 'Cropping Test';
?>
<div class="site-index">
<p>Cropping Test</p>
<?PHP
// ...
?>
</div>
我该怎么做?
解决方法:
查看render’s文档,您有几种选择:
The view to be rendered can be specified in one of the following formats:
- path alias (e.g. “@app/views/site/index”);
- absolute path within application (e.g. “//site/index”): the view name starts with double slashes. The actual view file will be looked for under the view path of the application.
- absolute path within module (e.g. “/site/index”): the view name starts with a >single slash. The actual view file will be looked for under the view path of $module.
- relative path (e.g. “index”): the actual view file will be looked for under $viewPath.
基于这些选择,您似乎将在应用程序内指定绝对路径,或者创建路径别名并使用该语法(应用程序位于“主站点视图”中的任何位置.)
因此,如果您想呈现{basePath} /views/site/my_partial.PHP,则可以执行类似$this-&r renderPartial(‘// site / my_partial.PHP’);的操作.在您看来.