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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:18:58+00:00 2026-06-09T06:18:58+00:00

I am new to PHP and Zend Framework. I met the error: Notice: Undefined

  • 0

I am new to PHP and Zend Framework. I met the error:

Notice: Undefined index: itemid in C:\xampp\htdocs\blogshop\application\views\scripts\item\tops.phtml on line 58

I don’t get why this error shows up.

public function topsAction() //tops action
{
    //$tops = new Application_Model_DbTable_Item();
    //$tops->getTops();
    $item = new Application_Model_DbTable_Item(); //create new Item object
    $this->view->item = $item->getTops();  //$this->view->item  is pass to index.phtml
}   

This is my controller code.

public function getTops()
{
    $row = $this->fetchAll('itemtype = "Tops"'); //find Row based on 'Tops'
    if (!$row) { //if row can't be found
        throw new Exception("Could not find Tops!"); //Catch exception where itemid is not found
    }
    return $row->toArray();
}

This is my getTops action in Model to get the rows with category ‘Tops’ in my database.

<?php foreach($this->item as $item) : ?>
    <?php echo $this->escape($this->item['itemid']);?> // This is where the error happens
    <img src="<?php echo $this->escape($item->image);?>" width="82" height="100">
    <?php echo $this->escape($this->item['itemname']);?>
    <?php echo $this->escape($this->item['description']);?>
    <?php echo $this->escape($this->item['itemtype']);?>
<?php endforeach; ?>

This is my code to display all the rows I have in my database.

  • 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-06-09T06:19:00+00:00Added an answer on June 9, 2026 at 6:19 am

    There is no index named itemid in your $this->item array, this is why you get the error.

    Also, your code here seems to be a bit wrong:

    <?php foreach($this->item as $item) : ?>
        <?php echo $this->escape($this->item['itemid']);?>
        <img src="<?php echo $this->escape($item->image);?>" width="82" height="100">
        <?php echo $this->escape($this->item['itemname']);?>
        <?php echo $this->escape($this->item['description']);?>
        <?php echo $this->escape($this->item['itemtype']);?>
    <?php endforeach; ?>
    

    Every $this->item inside the foreach statement should be replaced with $item for the iteration to work. So it will be $item['itemid'], $item['itemname'], etc. You are missing to get a level deeper into the array, rendering the iteration foreach useless.

    I guess $this->item looks something like this:

    array (
      1 => 
      array (
        'itemid' => 1,
        'itemname' => 'foobar',
      ),
      2 => 
      array (
        'itemid' => 2,
        'itemname' => 'bazqux',
      ),
    )
    

    This is why $this->item['itemid'] returns nothing, as it does not exist. $this->item[1]['itemid'] however does. What the foreach cycle helps you to do is that it walks (iterates) the whole $this->item array with each value represented as $item inside the cycle. In the first run, $item is $this->item[1], in the second, $item is $this->item[2], and so on, and so forth.

    So, change $this->item to $item inside the foreach construct.

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

Sidebar

Related Questions

im new in PHP and I want to know about PHP Zend Framework. What
I'm new to php and zend framework and fill very uncertain about following: For
I'm new to PHP and I recently started learning Zend Framework. What DAL are
I have been working on a new installation of a Zend Framework application for
I am new to zend framework I would like to know about bootstrap.php and
I'm new to php and zend framework, I've got this display screen which customer
I'm using PHP Zend framework for my web application. When users register, I send
I'm new to php, MVC and Zend Framework. I need to redirect to a
I'm working on a small php application using Zend Framework. I created a form
I'm trying to add a new folder to the application folder in zend framework,

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.