Page 1 of 1

Notice: Undefined index:

Posted: Mon Nov 26, 2007 12:05 am
by THE_AI
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?

Re: Notice: Undefined index:

Posted: Mon Nov 26, 2007 6:11 am
by Opie
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.