3

I got a little problem: I would like to create a form, which content is saved into 2 databases.

Field1 -> #__table_1
Field2 -> #__table_2

I'm doing this by extending the save-method in my model, which works fine.

But: In my JTable::store-method I'm checking the inputs of the user and sometimes I modify other fields according to the value of a specific field. Because not all values are stored in $this (because the fields do not exist in #__table_1) I have to work with $jinput to get these values.

Well - now I got a problem: I would like to create items by CLI doing this:

$data['id'] = NULL;
$data['field1'] = JFactory::getDate();;
$data['field2'] = $json;                        

// Lets store it!   
$row = JTable::getInstance('Ticket','BestiaTable');
$row->bind($data);
$row->check();
$store = $row->store(); 

if($store == true)  return $row->id;

else return false;

This does not work because during bind() the values that do not exist in #__table_1 are not available for store-process.

How can I change that? How can I push field2's value to the store-method?

2

I'm not sure if I'm understanding the question or not, but here's an example of code that I routinely use from the CLI using the model for saving/creating articles in #__content, hopefully it will help.

$basePath = JPATH_ADMINISTRATOR.'/components/com_content';
$model = new ContentModelArticle(array('table_path' => $basePath . '/tables'));
$article_id=0;    // 0 will add new article
$data = array(
    'id'    => $article_id,
    'catid' => $myCatId,
    'title' => 'My title',
    'alias' => 'My alias',
    .
    .  // other fields
    .
);
if(!$model->save($data)){
    return false;   // Save failed
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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