- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想将使用 ActiveForm 和 Html Helper 的表单 View 呈现的 html 输出存储到我的 Controller 中的一个变量中。
我试过将 renderPartial 的结果直接存储到一个变量,但没有成功:
$htmlform = Yii::$app->controller->renderPartial('_form', ['model' => $model]);
我也尝试过使用输出缓冲将输出回显到一个变量中,但我无法存储输出:
ob_start();
echo Yii::$app->controller->renderPartial('_form', ['model' => $model]);
$htmlform = ob_get_contents();
ob_end_clean();
查看文件:_form.php
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\models\Epic */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="epic-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'closed')->textInput() ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'organizationid')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
如果有人对解决方案有想法那就太好了..
最佳答案
我已经在一个简单的 ControllerAction 中尝试过这种方式并且工作正常......在 var_dump($test) 中有方面的结果
public function actionView($id)
{
$test = $this->renderPartial('_form', [
'model' => $this->findModel($id),
]);
var_dump($test);
}
关于php - Yii2 > 如何将 _form View 的 html 输出存储到字符串变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35910411/
默认情况下_form.as._p吐出: Subject: 而我需要 Subject: 标签和输入之间有中断。我该如何修改Django代码? 最佳答案 您只是不能再使用form.a
我正在重构脚手架模板,但遇到了这个问题: 我试图从模板 _FORM.GSP 调用服务(一些安全逻辑) - 但在代码部分,而不是在输出部分 我已经阅读并尝试了这里的建议:How do I call a
我正在使用 Carrierwave 将图像字段添加到基于 Ryan Bates 修订的 #196 截屏视频的 Rails 嵌套模型。 Carrierwave 位基于他的截屏 #253 问答模型嵌套在类
我正在使用 Node js 请求模块向网站发送发布请求。查看网站请求后,它使用“表单数据”作为有效负载。该页面的内容类型是“application/x-www-form-urlencoded”。我的脚
我按照 Rails 入门教程稍作修改(在模型和属性的名称上),但我发现使用表单部分有问题。 我的“_form.erb.html”如下所示: evi
我试图在网站上提交表单,当我运行代码时,它给了我错误: mechanize._form.ParseError: nested FORMs 所以我查了一下,在网站上,有 2 个表格相互嵌套。 我需要的第
我有一些 javascript 来控制 _form 部分中的某些字段如何根据单击的单选按钮工作。当我输入新记录(新)操作时,一切正常,但在编辑期间,呈现相同的 _form 部分,javascript
我知道这是一个简单的问题,但我不记得你是如何在 Rails 中自动生成 View _form、edit、index、new 等的。我以为当您生成 Controller 和模型时,它会自动创建这些项目,
我想将使用 ActiveForm 和 Html Helper 的表单 View 呈现的 html 输出存储到我的 Controller 中的一个变量中。 我试过将 renderPartial 的结果直
我是 Ruby on Rails 的新手。我使用脚手架为 admin 创建模型 View 和 Controller 现在我的一位前辈告诉我为管理员更改_form.html.erb。我不知道如何实现它。
我正在使用 Devise 来管理用户,我的目标是让当前用户与创建的记录一起保存。 我曾尝试将当前用户保存在 Controller 或 _form 中,但无论哪种方式都失败了! 谢谢大家的帮助。 我的记
出于教学目的,我想生成展示单选按钮的脚手架。您可以生成带有复选框的脚手架: rails generate scaffold Person name:string honest:boolean bool
我是一名优秀的程序员,十分优秀!