I am editing a Zend Framework 2 module and I came across the following code:
<?php
echo $this->partial('/menu', array('menu' => $this->menu));
?>
<hr />
<div class="myclass">
<h2>Heading</h2>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('register'));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('name'));
echo '<br />';
echo $this->form()->closeTag();
$this->inlineScript()->offsetSetScript(99, "
function checkFieldMatch() {
var field = $('#txtNewField').val();
//...
}
");
?>
</div>
Most of it was existing code, and now I have added some jQuery to it. The code has HTML, CSS, JavaScript/jQuery, and PHP. The code is located in my /vendor/$module/$submodule/view/$submodule/register/index.phtml
file.
Being under impression that Zend Framework 2 is latest and greatest heavyweight framework in PHP world, I cannot help but wonder what the heck happened when it came to principles of code separation. Surely, this abomination of a code above must be user-error. The authors of the code, me included, helped create this unbearable mess of technologies in one file. I suppose it shows that no matter how well-intentioned a complex framework is, when it comes to loose coupling components, someone can still put in 5 technologies into a short single file and have it look like hell.
While there may be several ways to do this, my question is:
What is the proper (recommended, designed) way to separate HTML, CSS, jQuery, JavaScript, PHP code in Zend Framework 2 so that each technology is separated into its own separate file and folder, where possible, while maintaining proper well-defined working connections (loose-coupling), and technology is embedded into each other directly only where it is absolutely required, or recommended via industry best-practices?
';` to get them out of their one line. That way they are less of an eye-sore. – Dennis Nov 08 '13 at 15:30