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 550361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:16:49+00:00 2026-05-13T11:16:49+00:00

I am using Zend Framework. I want the current user (if logged in) to

  • 0

I am using Zend Framework.

I want the current user (if logged in) to always be available to the view. In my Bootstrap.php file I currently have:

function _initViewHelpers()
{
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();

            // <snip> $view-> set some stuff

    $view->identity = Zend_Auth::getInstance()->getIdentity();
}

And my index.php file looks like:

require_once 'Zend/Application.php';  

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini');

$application->bootstrap();

$tblUser = new Model_DbTable_User();
Zend_Registry::set('user', $tblUser->getUser());

$application->run();

I want the Bootstrap to be something like this:

function _initViewHelpers()
{
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();

    $tblUser = new Model_DbTable_User();
    $user = $tblUser->getUser();
    Zend_Registry::set('user', $user);

    $view->user= $user;
}

If I try this, though, I get an error:

Fatal error:  Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Model_DbTable_User' in /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Db/Table/Abstract.php:754
Stack trace:
#0 /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Db/Table/Abstract.php(739): Zend_Db_Table_Abstract-&gt;_setupDatabaseAdapter()
#1 /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Db/Table/Abstract.php(268): Zend_Db_Table_Abstract-&gt;_setup()
#2 /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Db/Table.php(77): Zend_Db_Table_Abstract-&gt;__construct(Array)
#3 /var/www/application/Bootstrap.php(25): Zend_Db_Table-&gt;__construct()
#4 /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Application/Bootstrap/BootstrapAbstract.php(662): Bootstrap-&gt;_initViewHelpers()
#5 /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Application/Bootstrap/BootstrapAbstract.php(615): Zend_Application_Bootstrap_BootstrapAbstract-&gt;_executeResource('viewhelpers')
#6 /usr/local/php/ZendFramework-1.9.5- in /usr/local/php/ZendFramework-1.9.5-minimal/library/Zend/Db/Table/Abstract.php on line 754

So it looks like the database has not been setup by the framework at this point.

There must be a simple way to set the current user object in Zend Framework but I can’t figure it out.

  • 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-13T11:16:49+00:00Added an answer on May 13, 2026 at 11:16 am

    I ended up adding two methods to the Bootstrap:

    function _initDatabase()
    {
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 
            APPLICATION_ENV);
        $db = Zend_Db::factory($config->resources->db->adapter, 
            $config->resources->db->params);
        Zend_Registry::set('db', $db);
    }
    
    function _initUser()
    {
        $tblUser = new Model_DbTable_User(array('db' => Zend_Registry::get('db')));
        $user = $tblUser->getUser();
        Zend_Registry::set('user', $user);
    }
    

    Then I just do:

    $view->user = Zend_Registry::get('user');
    

    in _initViewHelpers()

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

Sidebar

Related Questions

I am using Zend Framework(MVC part of it), and need to either redirect user
I am using the Zend Framework. I have a controller named 'UserController' that has
I have been using the Zend Framework with an MVC configuration, read about Ruby
This is my first experience using the Zend Framework. I am attempting to follow
I'm using Zend Studio to do remote debugging of my php scripts on a
I'm using Zend Studio 6.1 for Eclipse, which comes bundled with the Subversive plug-in.
I've got a site using Zend Layouts and on certain pages I'd like to
I am attempting to pull some information from my tnsnames file using regex. I
Using Zend_Form, how would I create form elements like this: <input type=text name=element[1] value=
I'm using Zend_Form to output a set group of checkboxes: <label style=white-space: nowrap;><input type=checkbox

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.