0
votes

Ok here's the code:

<?php
echo $this->Form->templates([
    'nestingLabel' => '{{input}}<label{{attrs}}>{{text}}</label>',
    'formGroup' => '{{input}}{{label}}',
]);
echo $this->Form->hidden('thing_id', ['type' => 'text', 'value' => 1]);    

foreach($things as $thing) {   
    echo $this->Form->radio('thing_id', [
        [
            'id' => 'thing-id-' . $thing->id,
            'value' => $thing->id,
            'text' => 'test',
            'data-toggle' => 'button'
        ]
    ],
    [
        'label' => [
            'class' => 'button radius',
            'for' => 'thing-id-' . $thing->id,
            'text' =>
                '<figure><img src= ' . $thing->img . '/><figcaption>' .
                $thing->title .
                '</figcaption></figure>',
            'escape' => false  
        ], 
        'hiddenField' => false
    ]);
}
?>

This is the line that cakephp says is causing the error:

echo $this->Form->templates([
    'nestingLabel' => '{{input}}{{text}}',
    'formGroup' => '{{input}}{{label}}',
]);

Here's the error text:

Object of class Cake\View\Helper\FormHelper could not be converted to string

Any chance someone out there has come across this before?

So i ran this:

<?= $this->Form->templates([
        'nestingLabel' => '{{input}}<label{{attrs}}>{{text}}</label>',
        'formGroup' => '{{input}}{{label}}',
    ]) ?>

Without any of the other code in the form and still getting this error!

Warning (4096): Object of class Cake\View\Helper\FormHelper could not be converted to string [APP/Template/things/things/thing.ctp, line 17] Code Context include - APP/Template/things/things/thing.ctp, line 17 Cake\View\View::_evaluate() - CORE/src/View/View.php, line 992 Cake\View\View::_render() - CORE/src/View/View.php, line 952 Cake\View\View::render() - CORE/src/View/View.php, line 587 Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 611 Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 120 Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87 [main] - ROOT/webroot/index.php, line 36

1
Whenever receiving errors, please always post the complete error, that is, including the full stacktrace (ideally copied from the logs where it is available in a properly readable fashion), even if the problem might be obvious to people who are familiar with CakePHP!ndm

1 Answers

1
votes

well this is an embarrassing one!

Simple answer. Don't echo$this->Form->templates!

So that's the radio button working now. Except that the images aren't showing.

I think that might be something to do with routing.

Anyway there you go. Advice to all dyslexic people - if something simple isn't working then copy and paste the code from the docs again and go from there!