Automagic output fields in CakePHP?

I am currently using CakePHP "automatic" field elements for my CRUD forms.
By this I mean that I use

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

to generate everything.

This selects the correct element type and wraps everything in a div with the label <label> of the element.

Now I have some fields that cannot be edited, but I would like them to be displayed (so there really would not be a label, just a range, and instead of an <input> control, just text or a range.
I should also be able to arbitrarily control the contents of the "field value".

Is there a way to do this with $ form-> input?
I know that I can just create markup for all this, but it would look pretty ugly and very repeatable.

Thank!
Daniel

+3
source share
6 answers

You can always leave them as inputs, but remove the editing option. Adding 'readonly' => truethe input parameters must be added to input something like this: readonly="readonly".

+2
source

What about:

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

If this is too ugly, you can write your own helper:

<?php
class WhateverHelper extends AppHelper {
    var $helpers = array('Html');
    function whatever($fieldname) {
        return $this->Html->tag("span", $form->data[$fieldname]);
    }
}
?>
+1
source

:

$form->data["fieldname"]

. , , .

. .

+1

, CakePHP: - (

:

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

, .

, , , .

, -!

0

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

0
source

Source: https://habr.com/ru/post/1733221/


All Articles