2

I'm using tags in my components. Hm, well - I would like to use them ;-)

This is my form-declaration for tags:

    <field  name        =       "tags" 
            type        =       "tag"
            label       =       "JTAG" 
            description =       "JTAG_DESC"
            class       =       "inputbox span12 small" 
            multiple    =       "true" />

This is my getItem in my model:

/**
 * getItem function.
 * 
 * @access public
 * @param mixed $pk (default: null)
 * @return void
 */
public function getItem($pk = null)
{
    if ($item = parent::getItem($pk)) 
    {
        // Convert the metadata field to an array.
        $registry                   =       new JRegistry;

        if(isset($item->metadata))
        {
            $registry->loadString($item->metadata);
            $item->metadata         =       $registry->toArray();
        }

        if (!empty($item->id))
        {
            $item->tags             =       new JHelperTags;
            $item->tags->getTagIds($item->id, 'com_bestia.goal');
            $item->metadata['tags'] =       $item->tags;
        }
    }

    return $item;
}

And this is my table's constructor:

public function __construct(&$db)
{
    parent::__construct('#__bestia_goals', 'id', $db);
    JTableObserverTags::createObserver($this, array('typeAlias' => 'com_bestia.goal'));
}

In my table there's also an override for the store-method, because I have to prepare a Calendar-Field with format dd.mm.yyyy to be saved to MySQL DATETIME:

/**
 * store function.
 * 
 * @access public
 * @param bool $updateNulls (default: false)
 * @return void
 */
public function store($updateNulls = false)
{           
    if(!empty($this->dateofbirth))  // Prepare DOB to be saved in database
    {
        // Set this to a format the sql-table is able to save
        $date                       =           JFactory::getDate($this->dateofbirth);          
        $this->dateofbirth          =           $date->toSql(); 
    }

    // Use parent store method
    $result                         =           parent::store($updateNulls);    

    return $result;
}

Now my problem is - if I want to save the records, I'm getting this response:

Speichern fehlgeschlagen! Fehler:

Which is translated:

Error by saving! Error:

If I var_dump $result in my store-method, I'm getting back false. If I remove

    JTableObserverTags::createObserver($this, array('typeAlias' => 'com_bestia.goal'));

$result is true again.

What did I do wrong?

1

First of all this:

if(!empty($this->dateofbirth))  // Prepare DOB to be saved in database
{
    // Set this to a format the sql-table is able to save
    $date = JFactory::getDate($this->dateofbirth);          
    $this->dateofbirth = $date->toSql(); 
}

Should be in check() method. Then use this after parent::store($updateNulls = false) in your store method:

var_dump($this->_db->getErrorMsg());die;

to check what is causing the error. Alternatively you can use exceptions to catch the error:

try {
    $result = parent::store($updateNulls);
} catch(Exception $e) {
    die($e->getMessage());
}
0

when you install your component, you have to insert row to database in install.mysql.utf8.sql add this row

INSERT INTO `#__content_types` (`type_title`, `type_alias`, `table`, `rules`, `field_mappings`, `router`, `content_history_options`) VALUES
('Your Title', 'com_bestia.goal', '{\"special\":{\"dbtable\":\"#__yourtable\",\"key\":\"id\",\"type\":\"Content\",\"prefix\":\"PropertiTable\",\"config\":\"array()\"},\"common\":{\"dbtable\":\"#__ucm_content\",\"key\":\"ucm_id\",\"type\":\"Corecontent\",\"prefix\":\"YourtableTable\",\"config\":\"array()\"}}', '', '{\"common\":{\"core_content_item_id\":\"id\",\"core_title\":\"title\",\"core_state\":\"state\",\"core_alias\":\"alias\",\"core_created_time\":\"created\",\"core_modified_time\":\"modified\",\"core_body\":\"introtext\", \"core_hits\":\"hits\",\"core_publish_up\":\"publish_up\",\"core_publish_down\":\"publish_down\",\"core_access\":\"access\", \"core_params\":\"attribs\", \"core_featured\":\"featured\", \"core_metadata\":\"metadata\", \"core_language\":\"language\", \"core_images\":\"images\", \"core_urls\":\"urls\", \"core_version\":\"version\", \"core_ordering\":\"ordering\", \"core_metakey\":\"metakey\", \"core_metadesc\":\"metadesc\", \"core_catid\":\"catid\", \"core_xreference\":\"xreference\", \"asset_id\":\"asset_id\"}, \"special\":{\"fulltext\":\"fulltext\"}}', 'PropertiHelperRoute::getListingRoute', '{\"formFile\":\"administrator\\/components\\/com_properti\\/models\\/forms\\/listing.xml\", \"hideFields\":[\"asset_id\",\"checked_out\",\"checked_out_time\",\"version\"],\"ignoreChanges\":[\"modified_by\", \"modified\", \"checked_out\", \"checked_out_time\", \"version\", \"hits\"],\"convertToInt\":[\"publish_up\", \"publish_down\", \"featured\", \"ordering\"],\"displayLookup\":[{\"sourceColumn\":\"catid\",\"targetTable\":\"#__categories\",\"targetColumn\":\"id\",\"displayColumn\":\"title\"},{\"sourceColumn\":\"created_by\",\"targetTable\":\"#__users\",\"targetColumn\":\"id\",\"displayColumn\":\"name\"},{\"sourceColumn\":\"access\",\"targetTable\":\"#__viewlevels\",\"targetColumn\":\"id\",\"displayColumn\":\"title\"},{\"sourceColumn\":\"modified_by\",\"targetTable\":\"#__users\",\"targetColumn\":\"id\",\"displayColumn\":\"name\"} ]}')

please customize as your need

a hope this help...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.