Notice: Undefined index:

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
THE_AI
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sat Jun 03, 2006 4:33 pm
Contact:

Notice: Undefined index:

Post by THE_AI » Mon Nov 26, 2007 12:05 am

Well :) damn I don't understand what I do wrong.
I'm trying to get all the records from the database and display them in frontend.

My model look like this:

Code: Select all

class xxxModelxxx extends JModel {

  var $_data;

  function _buildQuery() {
  	$query = ' SELECT * FROM #__xxx';

  	return $query;
  }

  function getData() {
  	if (empty( $this->_data)){
  		$query = $this->_buildQuery();
  		$this->_data = $this->_getList( $query );
  	}

  	return $this->_data;
  }
}
My view.html.php like this:

Code: Select all

class xxxViewxxx extends JView {
	function display($tpl = null) {
		 $items =& $this->get( 'Data');

        $this->assignRef( 'items', $items );

		parent::display($tpl);
	}
}
So and now my template:

Code: Select all

<?php
defined('_JEXEC') or die('Restricted access'); ?>
<h1><?php var_dump($this->items); echo $this->items['author'];?></h1>
<h2>ala baala</h2>
My var_dump gives me the right array I'm looking for, but $this->items['author'] doesn't show me the author, rather than a notice message :(

Notice: Undefined index: book_name in xxx\tmpl\default.php on line 11

var_dump looks like this

Code: Select all

array(1) { [0]=>  object(stdClass)#117 (20) { ["id"]=>  string(1) "1" ["name"]=>  string(4) "well" ["author"]=>  string(11) "William well" } } 
Any ideas?
Well, now I will try to develop extensions :)

Opie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

Re: Notice: Undefined index:

Post by Opie » Mon Nov 26, 2007 6:11 am

It looks like you need to extract the object from the items array.  did you notice the second opening brace "{" in the array?

Code: Select all

array(1) { [0]=>  object(stdClass)#117 (20) [color=#f00]{[/color] ["id"]=>  string(1) "1" ["name"]=>  string(4) "well" ["author"]=>  string(11) "William well" } } 
The items array only contains one element.  That one element contains your named indexes.

I hope I have all of that right.  I'm not a php programmer, yet.
http://springhillalumni.org • Springhill High School Alumni Association


Post Reply