3

I'm currently using CakePHP's "automagic" field elements for my CRUD forms.
By this I mean I'm using the

echo $form->input('fieldname', $options);

method to generate everything.

This chooses the correct element type, and wraps everything into a div with a <label> element.

Now I have some fields that are not editable, but i'd like for them to show (so there wouldn't really be a label, just a span, and instead of the <input> control, there'd be simply some text, or a span.
I also need to be able to control the contents of the "field value" arbitrarily.

Is there a way to do this with $form->input?
I know I can simply generate the markup for all this, but it'd look pretty ugly, and it's very repetitive.

Thanks!
Daniel

4

6 回答 6

2

您始终可以将它们保留为输入,但取消编辑选项。添加'readonly' => true到输入参数应该添加到输入中,如下所示readonly="readonly"

于 2010-02-17T16:24:20.380 回答
1

您不需要(永远不应该!)触摸核心文件。

您可以基于内置的 FormHelper 创建自己的 FormHelper 并覆盖输入法。

下面是我如何覆盖 HtmlHelper 的 sort 方法来为分页表添加排序方向类:

http://richardathome.com/blog/cakephp-extend-paginatorhelper-indicate-sort-field-and-direction

于 2010-02-18T09:59:58.097 回答
1

关于什么:

$html->tag("span", $form->data["fieldname"]);

如果那太难看,您可以编写自己的助手:

<?php
class WhateverHelper extends AppHelper {
    var $helpers = array('Html');
    function whatever($fieldname) {
        return $this->Html->tag("span", $form->data[$fieldname]);
    }
}
?>
于 2010-02-17T16:22:23.033 回答
1

你最好这样做:

$form->data["fieldname"]

并用您需要的任何标记围绕它。如果需要,请按照 Richard 的建议添加您自己的助手。

但永远不要改变核心。它只会让你更头疼。

于 2010-02-18T16:11:07.980 回答
0

echo $form->input('something', array('div'=>false, 'label'=>false));

于 2010-02-19T00:11:24.860 回答
0

最后,我最终修改了 CakePHP :-(

我刚刚添加了执行此操作的选项:

echo $form->input('customer_id', array('type' => 'output', 'value' => 'xxxx' ));

这样做相对微不足道,尽管我宁愿不接触核心文件。

我在他们的错误系统中添加了有关如何执行此操作的详细信息,以查看他们是否会考虑在未来的版本中添加它。

希望这对某人有帮助!

于 2010-02-17T16:52:18.510 回答