GetData - Joomla! Forum - community, help and support


hi,

i followed hello world tutorials, , , looking @ core components tried make own component. i'm stuck following: want edit item (say greeting), model has method getdata retrieves record database. data loaded in view by:

code: select all

function display($tpl = null)
{
      $item =& $this->get('data');   
      parent::display($tpl);
}

and assigned template by

code: select all

$this->assignref('item', $item);


now extend view showing related items (say countries use particular greeting).
i made method getcountries() in model retrieves data table in database, , changed view adding:

code: select all

function display($tpl = null)
{
      $item =& $this->get('data');   
      $countries =& $this->get('countries');   
      parent::display($tpl);
}

code: select all

$this->assignref('item', $item);
$this->assignref('countries', $countries);


somehow countries don't show up... have site in debug mode , can see query isn't executed, don't know why.

somebody can help  ???

is assignref outside of display() function in view.html.php?

while following not have database code, works me.

view.html.php

code: select all

jimport( 'joomla.application.component.view');

/**
 * html view class helloworld component
 *
 * @package      joomla.tutorials
 * @subpackage   components
 */
class helloviewhello extends jview
{
   function display($tpl = null)
   {
      $item = $this->get('data');
      $countries = $this->get('countries');
      
      $this->assignref( 'item',   $item );
      $this->assignref( 'countries',   $countries );
      
      parent::display($tpl);
   }
}


model hello.php

code: select all

class hellomodelhello extends jmodel
{
   /**
    * gets greeting
    * @return string greeting displayed user
    */
   function getdata()
   {
      return 'hello, world!';
   }
   
   function getcountries()
   {
      $countries = array();
      
      $countries[] = 'abc';
      $countries[] = 'def';
      $countries[] = 'ghi';
      
      return $countries;
   }
}


tmpl code - default.php

code: select all

<?php // no direct access
defined('_jexec') or die('restricted access'); ?>
<h1><?php echo $this->item; ?></h1>
<?php foreach ($this->countries $country)
{
?>
<li><?php echo $country; ?></li>
<?php
}
?>





Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts