title: magento approach saving referer url and keywords
body: <p>My goal is to save on database the url referer and keywords when entering on any page of our store. I <a href="https://stackoverflow.com/questions/4006183/magento-passing-data-between-a-controller-and-a-block">checked this question and its answer</a> to try to get some light into my problem.</p>
  
  <p>The approach I'm following is:</p>
  
  <ol>
  <li><p>To have a block that will stick on the default layout so it will be loaded on each page (tested, is working). This block will read the referer by using the following code:</p>
  
  <p>$request['url'] = $this->getRequest()->getServer('HTTP_REFERER');</p></li>
  <li><p>Then call function passing the $request to a controller:
  This step I still do not know how to do it, using redirect? Or maybe by calling a dispatchEvent and on the controller having a <code>postAction</code> function?</p>
  
  <pre><code>//on the phtml file
  &lt;div&gt;
       &lt;?php
            $request['url'] = getRequest()-&gt;getServer(‘HTTP_REFERER’);
            Mage::dispatchEvent("allpagescontroller", $request);
       ?&gt;
  &lt;/div&gt;
  </code></pre></li>
  <li><p>The controller will instantiate my model and call the setters to update/insert neeeded values</p>
  
  <pre><code>//on the controller
  function postAction ($params)
  {
      $referer = $this-&gt;getRequest()-&gt;getPost();
  }
  </code></pre></li>
  <li><p>On the model I will have all the appropiate code to do the CRUD operations</p></li>
  </ol>
  
  <p>Is this correct? I'm trying to follow the Magento MVC approach by following these steps. For now I've all the code on the phtml file. I'm getting the referer, splitting it and instantiating the model to save everything. But I know this is not correct.</p>
  
  <p>On config.xml for now I have:</p>
  
  <blockquote>
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
      &lt;modules&gt;
          &lt;Dts_Allpages&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/Dts_Allpages&gt;
      &lt;/modules&gt;
      &lt;global&gt;
        &lt;models&gt;
            &lt;allpages&gt;
                &lt;class&gt;Dts_Allpages_Model&lt;/class&gt;
                &lt;resourceModel&gt;allpages_mysql4&lt;/resourceModel&gt;
            &lt;/allpages&gt;
            &lt;allpages_mysql4&gt;
                    &lt;class&gt;Dts_Allpages_Model_mysql4&lt;/class&gt;
                  &lt;entities&gt;
                    &lt;keywords&gt;
                        &lt;table&gt;keywords&lt;/table&gt;
                    &lt;/keywords&gt;
                    &lt;referencedpages&gt;
                        &lt;table&gt;referencedpages&lt;/table&gt;
                    &lt;/referencedpages&gt;
                &lt;/entities&gt;
            &lt;/allpages_mysql4&gt;
          &lt;/models&gt;
          &lt;blocks&gt;
              &lt;allpages&gt;
                  &lt;class&gt;Dts_Allpages_Block&lt;/class&gt;
              &lt;/allpages&gt;
          &lt;/blocks&gt;
          &lt;helpers&gt;
              &lt;allpages&gt;
                  &lt;class&gt;Dts_Allpages_Helper&lt;/class&gt;
              &lt;/allpages&gt;
          &lt;/helpers&gt;
          &lt;resources&gt;
              &lt;allpages_write&gt;
                  &lt;connection&gt;
                      &lt;use&gt;core_write&lt;/use&gt;
                  &lt;/connection&gt;
              &lt;/allpages_write&gt;
              &lt;allpages_read&gt;
                  &lt;connection&gt;
                      &lt;use&gt;core_read&lt;/use&gt;
                  &lt;/connection&gt;
              &lt;/allpages_read&gt;
          &lt;/resources&gt;
      &lt;/global&gt;&gt;
      &lt;frontend&gt;
        &lt;routers&gt;
            &lt;allpages&gt;
                &lt;use&gt;standard&lt;/use&gt;
                &lt;args&gt;
                    &lt;module&gt;Dts_Allpages&lt;/module&gt;
                    &lt;frontName&gt;allpages&lt;/frontName&gt;
                &lt;/args&gt;
            &lt;/allpages&gt;
        &lt;/routers&gt;
          &lt;layout&gt;
              &lt;updates&gt;
                  &lt;allpages&gt;
                      &lt;file&gt;allpages.xml&lt;/file&gt;
                  &lt;/allpages&gt;
              &lt;/updates&gt;
          &lt;/layout&gt;
      &lt;/frontend&gt;  
  &lt;/config&gt;
  </code></pre>
  </blockquote>