title: Proper Code-separation in Zend Framework 2
body: <p>I am editing a Zend Framework 2 module and I came across the following code:<br></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  echo $this-&gt;partial('/menu', array('menu' =&gt; $this-&gt;menu));
  ?&gt;
  &lt;hr /&gt;
  &lt;div class="myclass"&gt;
      &lt;h2&gt;Heading&lt;/h2&gt;
  &lt;?php
  
  $form = $this-&gt;form;
  $form-&gt;setAttribute('action', $this-&gt;url('register'));
  $form-&gt;prepare();
  
  echo $this-&gt;form()-&gt;openTag($form);
  echo $this-&gt;formRow($form-&gt;get('name'));
  echo '&lt;br /&gt;';
  echo $this-&gt;form()-&gt;closeTag();
  
  $this-&gt;inlineScript()-&gt;offsetSetScript(99, "
  function checkFieldMatch() {
      var field = $('#txtNewField').val();
      //...
  }
  ");
  
  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>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 <code>/vendor/$module/$submodule/view/$submodule/register/index.phtml</code> file.</p>
  
  <p>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.  </p>
  
  <p>While there may be several ways to do this, my question is:  </p>
  
  <blockquote>
    <p>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?</p>
  </blockquote>