0

I'm fairly new in Magento, what I'm trying to do is to get the request from URL and get the specific Parameter from it then pass it to Helper, in helper I need to check that specific parameter and run the correct function which is related to that specific parameter, Grateful if anyone can help me through this?

So, I already created my Controller file which is TestController.php

    <?php 

class Test_Request_TestController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $params = $this->getRequest()->getParams();
        foreach ($params as $key => $value) 
        {
            if($key == 'something')
            {
                echo Mage::helper('request')->getProducts();
            }
        }
    }
}

and here is my config.xml

<?xml version='1.0'?>
<config>
    <modules>
        <Test_Request>
            <version>0.0.1</version>
        </Test_Request>
    </modules>
    <frontend>
        <routers>
            <Test>
                <use>standard</use>
                <args>
                    <module>Test_Request</module>
                    <frontName>Test</frontName>
                </args>
            </Test>
        </routers>
    </frontend>
    <global>
        <helpers>
            <request>
                <class>Test_Request_Helper</class>
            </request>
        </helpers>
    </global>
</config>

and I've been created my helper

Data.php

<?php

class Test_Request_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function getProducts()
    {
        echo 'products';
    }
}

What I did is, I created function in helper class and I want to check the parameters of the URL under controller if the parameter is the same as the thing I want I want to call the function from helper, is that right ?? because I keep getting this error:

Warning: include(/var/www/html/magento/includes/src/Test_Request_Helper_Data.php): failed to open stream: No such file or directory  in /var/www/html/magento/includes/src/Varien_Autoload.php on line 93

#0 /var/www/html/magento/includes/src/Varien_Autoload.php(93): mageCoreErrorHandler(2, 'include(/var/ww...', '/var/www/html/m...', 93, Array)
#1 /var/www/html/magento/includes/src/Varien_Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('Test_Request_He...')
#3 /var/www/html/magento/app/Mage.php(547): spl_autoload_call('Test_Request_He...')
#4 /var/www/html/magento/app/code/community/Test/Request/controllers/TestController.php(12): Mage::helper('request')
#5 /var/www/html/magento/includes/src/__default.php(14015): Test_Request_TestController->indexAction()
#6 /var/www/html/magento/includes/src/__default.php(18399): Mage_Core_Controller_Varien_Action->dispatch('index')
#7 /var/www/html/magento/includes/src/__default.php(17933): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /var/www/html/magento/includes/src/__default.php(20705): Mage_Core_Controller_Varien_Front->dispatch()
#9 /var/www/html/magento/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#10 /var/www/html/magento/index.php(87): Mage::run('', 'store')
#11 {main}

I really don't know where this coming from, Please let me know if you have any idea how to fix this issue, thanks :)

2
  • Can you post the code you have so far? Either in here or upload your module to github and share the link. It is kinda hard to debug while blind. Also, how will the URL look? Theres a few different ways to pull it in.
    – kab8609
    Commented Dec 20, 2014 at 4:15
  • Hi I already edited my question, Let me know if you have any idea thanks :) Commented Dec 23, 2014 at 7:00

2 Answers 2

0

To get parameter from the request use below code in a method in any class,

$param = $this->getRequest()->getParam('paramname');

To get all parameter in the request,

$params = $this->getRequest()->getParams();

Then you need to pass this to helper so forex:-

Mage::helper('modulename/helpername')->methodgettingparam($param);

if your helper is Data.php then just use 'modulename' only.

Hope this is what you need.

5
  • Hi thanks for ur time and answer, I also get stock in one stage before to test this code I really need ur help to solve this problem :( it takes me 2 days already cannot fix this issue, I already create my custom module, the following code is my IndexController.php and config.xml file everything seems ok but I keep getting to 404 page!! I already searched a lot but nothing helped me to solve this problem, the IndexController.php is in this link link and my config.xml is in this link link, will appreciate if you can help me out Commented Dec 22, 2014 at 8:20
  • @SaghiGhorbani Ask this as a new question with what url you are trying.. Commented Dec 22, 2014 at 8:25
  • @SaghiGhorbani did you solve this question with my answer?. Commented Dec 22, 2014 at 8:26
  • Yeah ok I will ask this question as a new question, I tried with localhost/magento/productsData/index/index and also localhost/magento/index.php/productsData/index/index none of them worked!! I cannot get to this stage I totally stock in this stage to create my route and continue to use the code :( Commented Dec 22, 2014 at 8:30
  • Post it let see. Commented Dec 22, 2014 at 8:31
0

You don't need to do pass the parameter value explicitly to the Helper.

The class: Mage_Core_Model_App can be accessed from anywhere in Magento using the Mage super class' app() method. The class Mage_Core_Model_App has a method: getRequest() that provides you with the request object anywhere - Blocks, Helpers, Models even controllers.

So do this:  $paramVal = Mage::app()->getRequest()->getParam('paramkey');

Get Param() can also take a second param to stand as the default value to be returned in case the paramKey does not exist in $_REQUEST.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.