如何获取用于创建 SPF.js 响应数组的 yii2 注册资产列表?

How to get yii2 registered assets list for creating SPF.js response array?

我需要获取在页面中注册的 yii2 资产列表,以便为响应 SPF.js 请求创建数组 我在名为 ajax.php 的新布局中使用此代码

<?php
use yii\helpers\Html;
use app\assets\AppAsset;
use \yii\helpers\Json;

AppAsset::register($this);
$spf_data = [
    'title' => Html::encode($this->title),
    'head' => $this->beginPage() . Html::csrfMetaTags() . $this->head(),
    'body' => ['content' => $this->beginBody() . $content],
    "attr" => [
        'content' => [
            "class" => "container"
        ]
    ],
    'foot' => $this->endBody() . $this->endPage(),
];
echo Json::htmlEncode($spf_data);

我的问题是要将资产注册到页面,但我无法将它们放入我的数组中
我需要获取元标签列表,link 标签和数组头索引中的脚本
我该怎么办?

您可以使用此代码在您的控制器操作中获取脚本和样式

ob_start();
ob_implicit_flush(false);
$this->view->beginPage();
$this->view->head();
$this->view->beginBody();
$this->renderPartial($view, $params);
$this->view->endBody();
$this->view->endPage(true);
$style_script= ob_get_clean();

并在 $spf_data

中使用 $style_script
$spf_data = [
    'title' => Html::encode($this->title),
    'head' => $style_script,
    'body' => ['content' => $this->renderPartial('viewName')],
    "attr" => [
        'content' => [
            "class" => "container"
        ]
    ],
];

这段代码对我有用