1

I have ZF2 Application. I want to integrate it into Metronic Template, because it is good looking and professional template.In ZF2 Application there are Controller, Form and Model inside directory: module\application\src\application.

Forms are handled in Form and we just call it from view, that is:

echo $this->form()->openTag($form);
echo $this->formLabel($form->get('email'));
echo $this->formElement($form->get('email'));

echo $this->formLabel($form->get('password'));
echo $this->formElement($form->get('password'));

echo $this->form()->closeTag();

However in "Metronic" forms are handled in view, that is:

<form class="login-form" action="index.html" method="post">
<div class="form-group"> 
        <label class="control-label visible-ie8 visible-ie9">Username</label>
        <div class="input-icon">
            <i class="fa fa-user"></i>
            <input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Username" name="username"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label visible-ie8 visible-ie9">Password</label>
        <div class="input-icon">
            <i class="fa fa-lock"></i>
            <input class="form-control placeholder-no-fix" type="password" autocomplete="off" placeholder="Password" name="password"/>
        </div>
    </div>
</form>

So when I do it like "Metronic", then there are no need to use Form inside ZF2 directory module\application\src\application. Is it against the rules of ZF2? Or how should I do it to integrate this template. Give your suggestions please.

Skylink
  • 83
  • 1
  • 9

1 Answers1

0

Zend Framework 2 and to an even greater extent 3 are modular. There are no hard and fast rules. If you want to use only the MVC part then you can. If you feel you would benefit from the Form Module then you can use it.

If you are only going to use certain parts of the framework ensure that you are not pulling down additional dependencies by only including the parts you require in your composer.json file, i.e.

Good: composer.json

    "require": {
        "php": "^5.6 || ^7.0",
        "zendframework/zend-component-installer": "^1.0 || ^0.3 || ^1.0.0-dev@dev",
        "zendframework/zend-skeleton-installer": "^1.0 || ^0.1.3 || ^1.0.0-dev@dev",
        "zendframework/zend-mvc": "^3.0.1",
        "zfcampus/zf-development-mode": "^3.0"
},

Bad: composer.json

    "require": {
        "php": "^5.6 || ^7.0",
        zendframework/zendframework
    },

If you do want to use the Form Module you could do this by writing you own Form View Helpers classes and registering them like this:

public function getViewHelperConfig() {
    return array(
        'invokables' => array(
            'element' => 'YourNamespace\Form\View\Helper\MetronicElement',
        ),                
    );
}

I don't know anything about Metronic so unsure if this would be useful / feasible. Also not sure how much work this would be but it would allow you set create the correct structure and attributes for the HTML.

Purple Hexagon
  • 3,538
  • 2
  • 24
  • 45