Cakephp 3 自动将值设置为用户定义的表单
Cakephp 3 Automatically set values to a user defined form
我能够 add/edit/delete 使用 Cakephp FormHelper 创建的表单。
但我想使用我自己的表格 没有html 助手。而且是大表格。在编辑中,我设置了一个要查看的实体。我给元素起的名字和列名一样。
但未设置值。
视图在插件中。
谁能告诉我如何在用户定义的表单中自动设置值。
我在表单中创建了一个表单标签如下,希望设置"context"并出现值
<?php echo $this->Form->create( $company ); ?>
还有表格的结尾。
<?php echo $this->Form->end(); ?>
在表单标签之间有许多 html 表单元素。
我发布了其中一个,我为其设置了与列名相同的名称
<div class="form-group panel">
<h6 for="pt-name">Former Name1</h6>
<input type="text" name="company_former_name_one" placeholder="Former Name 1" class="form-control">
</div>
我的控制器代码:
public function profile( $id = null )
{
$company = $this->Companies->get( $id );
if ($this->request->is(['post','put']))
{
$post = $this->Companies->patchEntity($post, $this->request->data);
// $post->modified = date("Y-m-d H:i:s");
if( $this->Companies->save($post) )
{
}
}
$this->set('company', $company);
}
CakePHP 并不神奇
i cannot put the form helpers now, given the time line
最简单和最快方法是使用助手。
I was wondering if there is any default way to set form "context" when not using form helpers
没有
为此,框架需要解析模板中的静态 html,找出哪些位应该是动态的,应用一些 magic/assumptions,然后转储 [=34] =]. CakePHP 不能以这种方式工作。
使用助手
而不是静态 html,使用适当的辅助方法。例如FormHelper::text
<div class="form-group panel">
<h6 for="pt-name">Former Name1</h6>
<?= $this->Form->text('former_name1') ?>
</div>
这将生成如下内容:
<div class="form-group panel">
<h6 for="pt-name">Former Name1</h6>
<input name="former_name1" value="default" type="text">
</div>
我能够 add/edit/delete 使用 Cakephp FormHelper 创建的表单。
但我想使用我自己的表格 没有html 助手。而且是大表格。在编辑中,我设置了一个要查看的实体。我给元素起的名字和列名一样。
但未设置值。
视图在插件中。
谁能告诉我如何在用户定义的表单中自动设置值。
我在表单中创建了一个表单标签如下,希望设置"context"并出现值
<?php echo $this->Form->create( $company ); ?>
还有表格的结尾。
<?php echo $this->Form->end(); ?>
在表单标签之间有许多 html 表单元素。 我发布了其中一个,我为其设置了与列名相同的名称
<div class="form-group panel">
<h6 for="pt-name">Former Name1</h6>
<input type="text" name="company_former_name_one" placeholder="Former Name 1" class="form-control">
</div>
我的控制器代码:
public function profile( $id = null )
{
$company = $this->Companies->get( $id );
if ($this->request->is(['post','put']))
{
$post = $this->Companies->patchEntity($post, $this->request->data);
// $post->modified = date("Y-m-d H:i:s");
if( $this->Companies->save($post) )
{
}
}
$this->set('company', $company);
}
CakePHP 并不神奇
i cannot put the form helpers now, given the time line
最简单和最快方法是使用助手。
I was wondering if there is any default way to set form "context" when not using form helpers
没有
为此,框架需要解析模板中的静态 html,找出哪些位应该是动态的,应用一些 magic/assumptions,然后转储 [=34] =]. CakePHP 不能以这种方式工作。
使用助手
而不是静态 html,使用适当的辅助方法。例如FormHelper::text
<div class="form-group panel">
<h6 for="pt-name">Former Name1</h6>
<?= $this->Form->text('former_name1') ?>
</div>
这将生成如下内容:
<div class="form-group panel">
<h6 for="pt-name">Former Name1</h6>
<input name="former_name1" value="default" type="text">
</div>