My goal is to save on database the url referer and keywords when entering on any page of our store. I checked this question and its answer to try to get some light into my problem.
The approach I'm following is:
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:
$request['url'] = $this->getRequest()->getServer('HTTP_REFERER');
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
postAction
function?//on the phtml file <div> <?php $request['url'] = getRequest()->getServer(‘HTTP_REFERER’); Mage::dispatchEvent("allpagescontroller", $request); ?> </div>
The controller will instantiate my model and call the setters to update/insert neeeded values
//on the controller function postAction ($params) { $referer = $this->getRequest()->getPost(); }
On the model I will have all the appropiate code to do the CRUD operations
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.
On config.xml for now I have:
<?xml version="1.0"?> <config> <modules> <Dts_Allpages> <version>0.1.0</version> </Dts_Allpages> </modules> <global> <models> <allpages> <class>Dts_Allpages_Model</class> <resourceModel>allpages_mysql4</resourceModel> </allpages> <allpages_mysql4> <class>Dts_Allpages_Model_mysql4</class> <entities> <keywords> <table>keywords</table> </keywords> <referencedpages> <table>referencedpages</table> </referencedpages> </entities> </allpages_mysql4> </models> <blocks> <allpages> <class>Dts_Allpages_Block</class> </allpages> </blocks> <helpers> <allpages> <class>Dts_Allpages_Helper</class> </allpages> </helpers> <resources> <allpages_write> <connection> <use>core_write</use> </connection> </allpages_write> <allpages_read> <connection> <use>core_read</use> </connection> </allpages_read> </resources> </global>> <frontend> <routers> <allpages> <use>standard</use> <args> <module>Dts_Allpages</module> <frontName>allpages</frontName> </args> </allpages> </routers> <layout> <updates> <allpages> <file>allpages.xml</file> </allpages> </updates> </layout> </frontend> </config>