Yii 2: Loading a module view as a partial view into another application view

I need to load a module view as a partial view inside another application view. I don't know how to do this in the manual.

The view is completely independent of the module:

<?php
    // This is the module 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>

      

How can i do this?

+3


source to share


1 answer


Looking at the documentation , you have several options:

The displayed view can be specified in one of the following formats:

  • path alias (for example, "@ app / views / site / index");
  • an absolute path within the application (for example, "// site / index"): the view name starts with double slashes. The actual view file will be searched in the app's view path.
  • absolute path in the module (for example, "/ site / index"): the view name starts with s> with a single forward slash. The actual view file will be searched under the view path $ module.
  • relative path (eg "index"): the actual viewfile will be searched under $ viewPath.


Based on these choices, it looks like you would provide an absolute path in the application, or create a path alias and use that syntax (kind of the main site of the application? Wherever it is.)

So, if you wanted to display {basePath}/views/site/my_partial.php

, you would do something like $this->renderPartial('//site/my_partial.php');

in your view.

+3


source







All Articles