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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:36:33+00:00 2026-05-27T06:36:33+00:00

I’m trying to learn the zend framework by reading through a book. So far

  • 0

I’m trying to learn the zend framework by reading through a book. So far all the code in it has worked, but now I’m having trouble authenticating users. The book suggests doing this through an action helper and doctrine 2’s entity managers.

here’s the code i’m using for this

my authenticate helper class…

public function init()
{           

  // Initialize the errors array
  Zend_Layout::getMvcInstance()->getView()->errors = array();
  $auth = Zend_Auth::getInstance();
  $em = $this->getActionController()->getInvokeArg('bootstrap')->getResource('entityManager');    
  if ($auth->hasIdentity()) {
    $identity = $auth->getIdentity();

    if (isset($identity)) {     
      $user = $em->getRepository('Entities\User')->findOneByEmail($identity);
      Zend_Layout::getMvcInstance()->getView()->user = $user;                   
    }
  }
}

the entity repository function…

public function findOneByEmail($email)
{

$rsm = new ResultSetMapping;

$rsm->addEntityResult('Entities\User', 'a');
$rsm->addFieldResult('a', 'id', 'id');
$rsm->addFieldResult('a', 'email', 'email');
$rsm->addFieldResult('a', 'fname', 'fname');

$query = $this->_em->createNativeQuery(
  'SELECT a.id, a.fname, a.email FROM users a 
     WHERE a.email = :email',
  $rsm
);

$query->setParameter('email', $email);
return $query->getResult();    

}

On the page view, i’m using the following code to check that the user is logged in:

<?php 
if($this->user){ 
    ?>Welcome back, <a href="/user/"><?php echo $this->user->fname; ?></a> &bull; <a href="/user/logout/">Logout</a><?php 
} ?>

the if condition passes when i’m logged in, but it won’t print the user’s name.

here’s the error message I get on it:

Notice: Trying to get property of non-object in C:\Program Files (x86)\Zend\Apache2\htdocs\dev.test.com\application\views\scripts\user\index.phtml on line 3

Can anyone help me fix this?

  • 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-27T06:36:33+00:00Added an answer on May 27, 2026 at 6:36 am

    I think part of the problem is here:

    if (isset($identity)) {     
        $user = $em->getRepository('Entities\User')->findOneByEmail($identity);
        Zend_Layout::getMvcInstance()->getView()->user = $user;                   
    }
    

    It looks like findOneByEmail expects the email address as the parameter but the whole identity object is being passed.

    That probably causes return $query->getResult(); to return null or false so $view->user is not an object and has no property fname.

    I think in findOneByEmail you need to do something like $user = $em->getRepository('Entities\User')->findOneByEmail($identity->email); where $identity->email is the property that contains the email address.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,

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.