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

help me take decisions creating admin system

im creating new administration system and i want help taking some decisions

1 - which one is better Phalcon\Tag OR Phalcon\Forms for creating forms knowing that each form is related to a model

2 - is it a good idea in to make unified forms by using a default view contain code below and inherit from it to make fast default views?

<h2>
    Create {{modelName}}
</h2>

<fieldset>

    {% for element in form %}
        <div class="control-group">
            {{ element.label(["class": "control-label"]) }}

            <div class="controls">
                {{ element }}
            </div>
        </div>
    {% endfor %}

    <div class="control-group">
        {{ submit_button("Submit", "class": "btn btn-primary") }}
    </div>

</fieldset>


85.5k

i create my forms manually .. the reason is that first i made them automatic ( in a loop ) but after that i had so many if's inside the code i deleted the whole shit and created them 1 by 1 .

my field names match my textfields so everything is populated automatically ( framework takes care of it ) except for selects .. i have if's there :D and additional code obviously.

Honeslty i dont know, but copy/pasting div block content containing the fied and just have to swap the field name, is it worth it wasting tons of time and if statments just for that .. by writing it plain you have 0 chance of getting stuck at some point, while creating those templates and stuff, you might end up redesigning your already created tempaltes acrross different pages just because in "this" page there is this additional "stuff" .

And 1 year from now if you have to fix a bug, which one would it prefer to be. I know i prefer the simplest one, but thats just me.

Anyways, thats my toughts.

It all depends on your project. If you have a lot of simple form inputs, then your approach is fine.

If you have more complex forms (style+javascript), then creating them manually is more managable.



3.4k
edited May '17

It's depend if you want use Phalcon\Validation\Validator, I think using Phalcon\Forms\Form; should be appropriate ...

class MyForm extends Form
{
    public function initialize($entity = null, $options = array())
    {
        $id = new Hidden("id");
        $this->add($id);

        $title = new Text("title");
        $title->setLabel("Titre");
        $title->setFilters(array('striptags', 'string'));
        $title->addValidators(array(
            new PresenceOf(array(
                'message' => 'Titre obligatoire'
            ))
        ));
        $this->add($title);
    }
}
...
{{ text_field("title", "placeholder": "Titre de la page") }}
...