Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7547103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:22:05+00:00 2026-05-30T09:22:05+00:00

I want to do some database operations and get/set a cookie before the front

  • 0

I want to do some database operations and get/set a cookie before the front page loads. for which event would i make the observer? I haven’t gotten to the cookie creation yet in my research, right now i want to do some database manipulation at the event. I have an observer right now going off at controller_front_send_response_before and this is the error trace i’m getting.

Mage registry key "_singleton/" already exists

Trace:
#0 /var/www/html/app/Mage.php(192): Mage::throwException('Mage registry k...')
#1 /var/www/html/app/Mage.php(446): Mage::register('_singleton/', false)
#2 /var/www/html/app/code/core/Mage/Core/Model/App.php(1252): Mage::getSingleton(false)
#3 /var/www/html/app/Mage.php(416): Mage_Core_Model_App->dispatchEvent('controller_fron...', Array)
#4 /var/www/html/app/code/core/Mage/Core/Controller/Varien/Front.php(186): Mage::dispatchEvent('controller_fron...', Array)
#5 /var/www/html/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#6 /var/www/html/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#7 /var/www/html/index.php(86): Mage::run('', 'store')
#8 {main}

This is my config node:

<frontend>
    ... 
    <events>
        <controller_front_send_response_before>
            <observers>
                <type>singleton</type>
                <class>Foo_Bar_Model_Observer</class>
                <method>controllerFrontSendResponseBefore</method>
            </observers>
        </controller_front_send_response_before>
    </events>
</frontend>

And this is my observer model

class Foo_Bar_Model_Observer
{
    public function controllerFrontSendResponseBefore(Varien_Event_Observer $observer)
    {
         $id = 1;
         $theVisitors = Mage::getModel('visitors/visitor');
         $theVisitors->load($id);  
         $numVisits = (int)$theVisitors->getNumvisits();
         ++$numVisits;
         $theVisitors->setNumvisits($numVisits);
         $theVisitors->save();
    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:22:06+00:00Added an answer on May 30, 2026 at 9:22 am

    See the switch statement in Mage_Core_Model_App::dispatchEvent(). You aren’t declaring a <model> node in your observer configuration – you have a <class> node. Interestingly, Mage::getSingleton() is poorly coded. The test to see if the singleton instance should be created and registered doesn’t handle the prototyped key of _singleton/!

    Now for your cookie. Mmm cookies. You’re observing a proper event for cookie manipulation (evident in the comment from Mage_Core_Controller_Varien_Front::dispatch()). You can also observe controller_action_predispatch. These will trigger for every page view, though, so you need to implement first-time-visitor logic in your observer. Also, you might have some dumbed-down code as an example here, but obviously the front page isn’t the only initial point of entry (I assumes that’s what you are going to do with cookies). There is an easily-targeted event in the CMS router, Mage_Cms_Controller_Router – you can use that for home page views.

    I’d be remiss to not tell you that there is a visitor logging mechanism in place (see the log_* tables).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to conduct some database operations on a scheduled basis, I could:
I I have a linq-to-sql database in which I want to log some of
There is some html text stored in the Database which I want to show
I want to do database operations in AutoIt. I written some code for it,
I have a class which does operations on the database, but I want to
I want to replicate some of data that exists in my database. I want
I want to generate some formatted output of data retrieved from an MS-Access database
I want to perform cascade delete for some tables in my database, but I'm
I Want Print DataBase Schema in Microsoft Sql Server Compact Edition. Maybe Exist Some
I want to ship a default SQLite database, with some predefined key/value pairs in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.