2

I have a news-module.

It got a Router.php.

At the moment, I validate in there, if theres an entry in DB for the URL it wants to rout to. If yes -> got to my news_view.phtml -> if not -> 404

What I want to achieve is to transfer the already loaded collection to my view because I dont want to load it twice. Once for validation in Router and then to display Data in view.

I know bout parameters, but is it a good idea to transfer like 50 lines news-text over parameters?

May I miss something totally here :-/

May someone of you got completely different approach. I am open for everything! Thx in forward!

3 Answers 3

1

You can use the Mage::register for this, here you can store data and retreive it in some other place.

To register a variable use:

Mage::register('some_name', $var);

Then to retreive the value simply use:

$my_var = Mage::registry('some_name');

And if you want to unload the variable you can use:

Mage::unregister('some_name');

The values stored in the register are only available during the active request, when you reload your page the register is flushed.

2
  • you have been the first, so you get the point! hope this is the right way to do it. Commented Sep 27, 2013 at 8:11
  • Damn it...19 seconds :). @StefanGregori. Yep...that's the right way to do it.
    – Marius
    Commented Sep 27, 2013 at 8:14
0

First of all I don't know why you get 50 lines in the collection. You should get one or none.
Maybe you should have a different approch on the validation of the url. Add a limit of 1 to the collection.
But anyway...you can use Mage::register to remember the loaded data.

Mage::register('news_data', $newsData);

And in the news view page just check:

$newsData = Mage::registry('news_data');
if (!$newsData){
   $newsData = 'Load data again'
}
2
  • The meaning by "50 lines" was like my news text(content) itself could be like 50 lines which I dont wanted to transfer with setParam(). Thx for pointing out Mage::register! Commented Sep 27, 2013 at 7:59
  • Oh. I get it now. Try to use the register method.
    – Marius
    Commented Sep 27, 2013 at 8:02
0

My way to find out what is wrong with my adminhtml module: I've added logging in

Mage_Core_Controller_Varien_Router_Standard::collectRoutes() (at the end)

mage::log("collectRoutes:". print_r($this->_modules,1),1,'router.log');

and also in Mage_Core_Controller_Varien_Router_Standard::getControllerFileName mage::log("Mage_Core_Controller_Varien_Router_Standard::getControllerFileName\n $file\n",1,'router.log');

and Mage_Core_Controller_Varien_Router_Standard::validateControllerFileName

 mage::log( "Mage_Core_Controller_Varien_Router_Standard::validateControllerFileName\n $fileName\not valid/not readable\n",1,'router.log');

from these logs I've found out what exactly the router is searching and fixed the issue

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.