We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



7.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.



38.8k

Understood and thanks for the clarification :)



38.8k

@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 :)



7.9k

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