我有一个ManyToMany
我闯入OneToMany
和ManyToOne
关系.我想构建一个具有复选框而不是集合的表单,我正在使用'DoctrineObject'保湿器,但它不起作用,我不知道出了什么问题.
我从我的代码中删除了所有其他不相关的字段.
角色实体:
/**
* @orm\Entity
* @orm\Table(name="roles")
*/
class RolesEntity extends HemisEntity {
/**
* @orm\Id
* @orm\Column(type="integer");
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @orm\Column(name="role_code",type="string")
*/
protected $roleCode;
/**
* @orm\OneToMany(targetEntity="RolesPermissionsEntity", mappedBy="role", cascade={"persist"})
*/
protected $rolePermissions;
public function __construct()
{
$this->rolePermissions = new ArrayCollection();
}
public function setRolePermissions($rolePermissions)
{
$this->rolePermissions = $rolePermissions;
return $this;
}
public function addRolePermissions(Collection $rolePermissions)
{
foreach ($rolePermissions as $rolePermission) {
$rolePermission->setRole($this);
$this->rolePermissions->add($rolePermission);
}
}
public function …
Run Code Online (Sandbox Code Playgroud) 对于我们的新项目,我们已经开始使用Zend Framework 2和Dojo 1.8.ZF2有一个完全重写的表单模块,现在它具有用于一对多关系的新CollectionElement.关于UI我发现,dgrid最适合这种关系(使用编辑器列插件),所以我开始扩展FormCollection,FormRow和FormElement视图助手,这样他们就可以渲染所需的dgrid.一切都很好,直到我意识到,我不能为dgrid小部件设置每行输入名称.
我开始使用ZF2文档来修复表单集合.可以看到,集合输入元素具有类似数组的名称
order[products][0][name]
order[products][0][price]
order[products][1][name]
order[products][1][price]
Run Code Online (Sandbox Code Playgroud)
另一方面,dgrid的配置是基于列的,所以我可以有一个列定义
editor({
field: "_dojo_textbox_505ee3a390d705_26717315",
label: "Name",
editorArgs: {
name: "order[products][{index}][name]",
}
}, TextBox)
Run Code Online (Sandbox Code Playgroud)
此列定义将为所有行定义相同的窗口小部件名称,这不适用于ZF2集合数据格式要求.
我也尝试过这样命名列:
order[products][]
Run Code Online (Sandbox Code Playgroud)
哪个有效,但不允许所需的格式
order[products][][name]
Run Code Online (Sandbox Code Playgroud)
也许有办法发布这样的数据:
order[products][name][]
Run Code Online (Sandbox Code Playgroud)
然后让它转换,但解决方案看起来不正确.除此之外,我试图生成可重用的代码,并希望避免每个表单的数据修改.
由于我非常努力避免onSubmit/onClick事件处理进行数据转换,因此有两种可能的解决方案:1.使dgrid能够设置每行小部件名称2.使ZF2表单理解一些非标准的POST格式集合
不幸的是,我没有想法,这些解决方案是如何完成的,所以如果你能帮我解决这个问题,我将非常感激!
由于这与我当前的问题有些相关,我将把它放在这里作为一个附带问题:除了这个UI解决方案,你还使用什么来实现与dojo的一对多表单接口?
我正在使用Zend/Form向我的页面添加表单.
我通过定义如下来添加元素:
$this->add(array(
'name' => 'value',
'attributes' => array(
'type' => 'text',
'id' => 'value',
'autocomplete' => 'off',
'placeholder' => 'Cost',
),
'options' => array(
'label' => 'Cost',
),
));
Run Code Online (Sandbox Code Playgroud)
如您所见,有一个'label'=>'cost'节点,这会生成一个与input元素一起使用的标签.
如何向此标签添加类,属性?
我没有得到它!..可以请有人解释,如何翻译表格标签?一个简单的例子就是很棒.
先感谢您!
class Search\Form\CourseSearchForm
...
class CourseSearchForm extends Form {
...
public function __construct(array $cities) {
parent::__construct('courseSearch');
...
$this->add(array(
'name' => 'city',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Stadt',
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
));
...
}
}
Run Code Online (Sandbox Code Playgroud)
查看脚本/module/Search/view/search/search/search-form.phtml
<?php echo $this->form()->openTag($form); ?>
<dl>
...
<dt><label><?php echo $form->get('city')->getLabel(); ?></label></dt>
<dd><?php echo $this->formRow($form->get('city'), null, false, false); ?></dd>
...
</dl>
<?php echo $this->form()->closeTag(); ?>
<!-- The formRow(...) is my MyNamespace\Form\View\Helper (extends Zend\Form\View\Helper\FormRow); the fourth argument of …
Run Code Online (Sandbox Code Playgroud) 在我目前的ZF2项目中,我有一个Form
具有多层嵌套Fieldset
s 的复合体,它反映了要在后台保存的对象的结构.目前,如果数据有效,数据将直接发送到Controller
数据库并保存到数据库.
现在应该实现一个中间步骤:用户应该有机会在输入数据保存到数据库之前检查输入数据.如果他决定,这是正确的,表格数据应该提交并保存到数据库中; 如果用户决定必须编辑表单,他应该能够返回到表单并进行更正.(当然是循环中的所有内容,直到用户对表单感到满意并提交它.)
这意味着,需要预览页面.这个页面/ action
应该获取数据并以某种方式显示它(作为表格或者然而).数据需要暂时存储在某处,并准备好"保湿"到Form
对象并保存.如果用户想要更新表单,则应该恢复表单.
我该如何实现这个要求?
UPDATE
我正在寻找服务器端解决方案.预览应该是新页面,而不是同一页面上的JavScript /客户端生成的HTML(用于跟踪和其他目的).
我有一个非常复杂的形式,有几个嵌套的Fieldset
s和Collection
s.表单的某些部分是常量,其他部分是可变的:
BasicSettings EndpointBasicSource(常量部分)EndpointBasicTarget(常量部分)SpecificSettings EndpointType {TYPE}源(可变部分)EndpointType {TYPE}目标(可变部分)
在EndpointBasicSource
和EndpointBasicTarget
包含ServerFieldset
,它提供的Field
server_name
.这意味着:表单至少包含2
server_name
Field
s.
在SpecificSettings
取决于EndpintType
否,一方或双方可以包含服务器Collection
(options.target_element.type => ServerFieldset
),其中包含最多5
服务器.
这是一个强烈简化的架构:
现在服务器应该是唯一的(在server_name
表单中的所有字段中,值可能不会重复).但是怎么做呢?问题是,ServerFieldset
通过多个其他Fieldset
s/Collection
s 注入,并且唯一性验证需要与server_name
Field
所有s中的s 相关.
如何解决这个问题server_name
并对整个表单中的所有内容进行唯一性验证?
zend-form zend-framework2 zend-form2 zend-form-collection zend-form-fieldset
Zend Form 2构建了Fieldsets中的所有元素.(Zend\Form\Form扩展Fieldset - Form :: add调用parent :: add)
如果我只是将元素添加到表单中,我可以通过它获取它们$form->getElements()
如果我使用字段集我可以通过它
foreach($form->getFieldsets() as $fieldset){
$elements = $fieldset->getElements();
}
Run Code Online (Sandbox Code Playgroud)
但想象一下我添加一些隐藏字段,然后是字段集,最后添加一个提交按钮的表单.
如何以正确的顺序获取元素/字段集?
这背后的原因,我正在研究一个视图帮助器,它允许我通过简单的调用视图助手来打印表单.
我不想通过调用调用每个表单元素formRow()
(我知道Form2背后的概念 - 将逻辑与表示分离)
任何帮助深表感谢.TIA
我在zf2 github上写过这篇文章但还没有人回答.但也许这不是一个错误,我做错了什么.这是我的代码:
字段集
class TestFieldset extends Fieldset implements
InputFilterProviderInterface
{
public function __construct($name)
{
parent::__construct($name);
$this->add(array(
'type' => 'text',
'name' => 'test'
));
}
public function getInputFilterSpecification() {
return array(
'test' => array(
'filters' => array(
array('name' => 'StringTrim')
),
'validators' => array(
array('name' => 'NotEmpty')
)
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
形成
class TestForm extends Form
{
public function __construct($name = null, $options = array()) {
parent::__construct($name, $options);
$fieldset = new TestFieldset('test-fieldset');
$this->add($fieldset);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器动作 …
我在ZF2应用程序中拥有以下类和模块配置,并且出现以下错误:
While attempting to create applicationformuserform(alias: Application\Form
\UserForm) an invalid factory was registered for this instance type.
Run Code Online (Sandbox Code Playgroud)
UserFormFactory.php
<?php
namespace Application\Factory\Form;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Application\Form\UserForm;
class UserFormFactory implements FactoryInterface {
public function createService(ServiceLocatorInterface $serviceLocator) {
$services = $serviceLocator->getServiceLocator();
$entityManager = $services->get('Doctrine\ORM\EntityManager');
$form = new UserForm($entityManager);
return $form;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
UserForm.php
<?php
namespace Application\Form;
use Zend\Form\Form;
use Zend\InputFilter\InputFilterProviderInterface;
use Doctrine\ORM\EntityManager;
class UserForm extends Form implements InputFilterProviderInterface {
protected $entityManager;
public function __construct(EntityManager $entityManager) {
parent::__construct();
$this->entityManager = $entityManager; …
Run Code Online (Sandbox Code Playgroud) 我班上有这个
$inputFilter->add(
$factory->createInput(array(
'name' => 'precio',
'required' => true,
'validators' => array(
array(
'name' => 'Float',
'options' => array(
'min' => 0,
),
),
),
))
);
Run Code Online (Sandbox Code Playgroud)
当我输入像 5 或 78 这样的整数时,一切似乎都没有问题,但是当我尝试输入像 5.2 这样的数字时,我收到了下一条错误消息
输入似乎不是浮点数
我已经按照Zend Framework 2的教程进行了操作,我在渲染表单上看到,绑定标签的约定是将input元素包装在label标签中,而不是使用'for'属性.虽然本教程没有涵盖它,但我(正确地)推断出属性数组允许在输入元素本身上设置类,但我真正想要做的是将类应用于选项下定义的标签.
这是教程中使用的示例(来自AlbumForm.php
):
$this->add(array(
'name' => 'title',
'attributes' => array(
'class' => 'required', // <- I added this
'type' => 'text',
),
'options' => array(
'label' => 'Title',
),
));
Run Code Online (Sandbox Code Playgroud)
这将呈现如下:
<label><span>Title</span><input name="title" class="required" type="text" value=""></label>
Run Code Online (Sandbox Code Playgroud)
或者,我可以将类应用于span标记,但我更喜欢在标签上使用类,然后使用css子选择器作为span和input元素
我重新阅读了教程以及相应部分的注释,甚至深入研究了Zend\Form API文档本身,我没有看到如何以这种方式声明表单元素时将类属性应用于标签.
另一个带有表单渲染的小挑剔是它看起来是内联呈现的,表单元素之间没有换行符.我通过在视图脚本(add.phtml
和edit.phtml
)中添加换行符来解决这个问题,如下所示:
echo $this->formRow($form->get('title')) . "\n";
Run Code Online (Sandbox Code Playgroud)
但是,对于视图中的每个回显表单语句而言,这似乎很痛苦,并且formCollection()
还使用内联呈现整个表单输出.出于易读性的目的,我希望在查看源代码时至少有适当的换行符(我也希望适当的缩进,但这似乎是一个很高的顺序,因为即使IDE在大多数情况下都会出错)
那么,我是否缺少这些问题的内置选项,或者是一种定义工厂或帮助器的方法?如果我需要编写帮助程序,我希望它适用于所有模块.
有没有人有这样的例子:Zend Framework多页表单
但是对于使用Zend\Session的Zend Framework 2?
zend-form2 ×12
zend-framework2 ×12
php ×4
forms ×2
label ×2
zend-form ×2
dgrid ×1
doctrine-orm ×1
dojo ×1
preview ×1
translate ×1
translation ×1