Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Understand "setLabel"

Hi there,

I'm trying to understand the use/value of setLabel?

$remember->setLabel('Remember me');

I pulled this code out of one of the Phalcon GitHub repos. It's set in a Form class but isn't referenced anywhere (that I can see) in templates or phtml files.

I guess my question is, what is the value of this and how does it help? Initially, I thought that when I rendered the element it referred to, the element would have a label generated for it.

Thanks.



5.9k
Accepted
answer
edited Apr '14

for HTML markup <label> and <input> (or checkbox, select etc) are different elements, phalcon does not produce a pair of elements, you have to create them yourself in the view file

<label for="remember">
    <?php echo $form->getLabel('remember'); ?>
</label>
<?php echo $form->render('remember'); ?>

looks like it is not very useful, but it helps me a lot in cases where i want to create multilingual forms, as the label text can be retrieved from translation arrays in the form file level along with validation and error messages.



22.6k

Understood and thanks for the clarification :)



22.6k

@humugus - after playing with this today, I can confirm that $form->label() does in fact render an HTML label. getLabel is a property accessor whereas label() & render() are methods.

This is very cool :)



5.9k

i was not aware of that ! thank you for that tip :D