Help with the component tutorial - Joomla! Forum - community, help and support


hi folks,

im learning develop joomla components, following tutorial.
http://docs.joomla.org/developing_a_mod ... _-_part_01

in tutorial, database table has 2 columns, id , greeting. administration, can add greetings , select them display on site frontend.

my component's database table has 3 columns. im trying assign data database variables use in component can sucessfully retrieve 1 piece of data, per way tutorial component is.

i believe variables passed down through these 3 files...(in reverse order)

code: select all

################################
# file 1) site/views/mycom/tmpl/default.php
################################

<h1>greeting: <?php echo $this->msg; ?></h1>
<p>my other field 1: <?php echo $this->myotherfield1; ?></p>

###############################
# file 2) site/views/mycom/view.html.php
###############################
<?php
defined('_jexec') or die('restricted access');
jimport('joomla.application.component.view');
class mycomviewmycom extends jview
{
   function display($tpl = null)
   {
   
      $this->msg = $this->get('msg');
      $this->myotherfield1 = $this->get('myotherfield1'); // doesnt work
      $this->myotherfield2 = $this->get('myotherfield2'); // doesnt work
      $this->myotherfield3 = $this->get('myotherfield3'); // doesnt work
      
      if (count($errors = $this->get('errors')))
      {
         jerror::raiseerror(500, implode('<br />', $errors));
         return false;
      }
      parent::display($tpl);
   }
}
#######################
# file 3) site/models/mycom.php
#######################
<?php

defined('_jexec') or die('restricted access');
jimport('joomla.application.component.modelitem');
class mycommodelmycom extends jmodelitem
{
   protected $msg;
   protected $myotherfield1; // doesnt work
   protected $myotherfield2; // doesnt work
   protected $myotherfield3; // doesnt work
   
   public function gettable($type = 'sproj', $prefix = 'sprojtable', $config = array())
   {
      return jtable::getinstance($type, $prefix, $config);
   }
   public function getmsg()
   {
      if (!isset($this->msg))
      {
         $id = jrequest::getint('id');
         $table = $this->gettable();
         $table->load($id);
         $this->msg = $table->greeting;
         // have here other fields database table, adding them in doesnt work. can seem work if swap above line "$this->msg = $table->myotherfield1;"
      }
      return $this->msg;
   }
}

it seems variable assigning process dependant on function called getmsg - line 17 of last file. function isn't called elsewhere in of components scripts!!! wtf?!

can help? im totally confused this.

i figured out. after decades of pain , sweat have been rewarded efforts.

i added in new function below "getmsg()", called "getmyotherfield1()", , changed references "msg" "myotherfield1". (4 of them).

code: select all

#######################
# file 3) site/models/mycom.php
#######################
   public function getmyotherfield1()
   {
      if (!isset($this->myotherfield1))
      {
         $id = jrequest::getint('id');
         $table = $this->gettable();
         $table->load($id);
         $this->myotherfield1 = $table->myotherfield1;
      }
      return $this->myotherfield1;
   }

and followed suit way msg vars requested in view.html.php

code: select all

###############################
# file 2) site/views/mycom/view.html.php
###############################
      $this->msg = $this->get('msg');
      $this->desc = $this->get('myotherfield1');

it seems function parameters meant ripped part of function name , placed on end in parameter form. hella odd me. never got memo one!! >:-[ guess don't know enough php yet, right?





Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support