php - 在 CAKEPHP 中获取 .ctp 文件的 html
问题描述
我已经使用cakephp
. 现在我有一些数据要在某些逻辑上呈现。此数据应显示为包含一些输入和其他字段的页面。
一件事是在javascript
side 中执行此操作,但在javascript
.
我正在研究的其他解决方案是将数据传递给.ctp
文件。获取html
并将其传递给我的内容。
我正在尝试这样做
$html = $this->render('myview');
$this->set('html', $view);
但它将 myview 呈现为页面而不是 html 以显示给我的视图。
解决方案
按照代码实现相同,(此代码在控制器的方法/动作中)
//Variables used in view
$data = $this->Admins->newEntity();
// create a builder
$builder = $this->viewBuilder();
// configure as needed
$builder->setLayout('default');
$builder->setTemplate('/Admins/login'); //Here you can use elements also
$builder->setHelpers(['Html']);
// create a view instance
$view = $builder->build(compact('data')); //Pass the variables to the view
// render to a variable
$output = $view->render();
//Print output
pr($output);
die;
推荐阅读
- visual-studio - 指定类或方法的特殊着色
- react-native - 当我想运行 debugger-ui react-native-debugger 时,react-native 应用程序崩溃
- excel-formula - 如何从不包括假期的结束天数计算
- python - Django 请帮我在html页面上放置一个复选框和一个带有发送按钮的邮箱
- java - 使用 GSON JsonReader 读取一个简单的 JSON 文件
- node.js - 我的 cookie 未在 studio.apollographql explorer 的浏览器中设置
- c# - 如果条件在表内
- javascript - MUI - React 无法识别 Datepicker 中 DOM 元素上的“renderInput”道具
- python - Scikit-learn:NameError:未定义名称“load_iris”
- java - 在 PayUCheckoutPro Payumoney PaymentGateways 集成中找不到明确的活动类