Hot answers tagged

8 votes
Accepted

What does JTable's bind function do and why it is useful?

Your form is defined by your XML form (typically located in models/forms). You choose to have the same names as those in your database as those field names but actually it isn't compulsory. You can ...
user avatar
6 votes
Accepted

Where is class $tableClass defined?

$tableClass is a variable. You won't find a class named "tableClass". It's just a placeholder for the real class name which will be generated at the beginning of the getInstance method. Take a look ...
user avatar
  • 3,693
4 votes
Accepted

Store data to other table and get the id

$row contains inserted data with PK. So $row->id is id of the saved data. So you can do public static function CreateMail($userid, $title, $state = 1) { $maildata['userid'] ...
user avatar
  • 570
4 votes
Accepted

Delete items of database via CLI

It's been awhile since I've done this, but as I recall putting this within doExecute should do what you want. $basePath = JPATH_ADMINISTRATOR.'/components/com_content'; require_once $basePath.'/...
user avatar
  • 7,685
4 votes
Accepted

Find user by email

Joomla\CMS\Table\User::load() can only load rows by user ID. Use database query to get user ID by email and pass it to table's load() method: $db = JFactory::getDbo(); $query = $db->getQuery(true) ...
user avatar
  • 8,581
4 votes
Accepted

JTable return associative array instead of object

$table->getProperties() already returns an array. You need to remove ArrayHelper::toObject() call which converts the array to an object.
user avatar
  • 8,581
3 votes
Accepted

Why does Joomla have both models and tables?

Class JTable is created to work strictly on database object. Table object should create,modify,delete,check data in database. It can be used in many models, helpers, modules. Single model some times ...
user avatar
3 votes

A foreign key field not updating as NULL

I managed to override the model save() method by calling the bind() and store() and store NULL values. if ($data['leavepack_id'] == '') $data['leavepack_id'] = NULL; $table = $this->...
user avatar
  • 2,651
3 votes

What does JTable's bind function do and why it is useful?

The Form does not know anything about the fields in your database. It's getting its fields by your XML definition. The bind() function just adds the data to the object, while store() will post the ...
user avatar
2 votes

JTable store() returns true but no row gets inserted

I believe, you want to bind your data at database level with primary-foreign key, Right? But FYI, Joomla itself is not using their data that way. Tables of Joomla does not use foreign key bindings at ...
user avatar
2 votes

Working with Entities and Repositories in Joomla

I don't know if there is a better way. Joomla has been developed more in a historic way, whereas both Symfony1 and 2 had a clean slate approach. They are also build for different purposes, Joomla's ...
user avatar
  • 953
2 votes

How to get the generated id after a successful INSERT query?

Solved it :-) Just define $db = JFactory::getDbo(); and after $db->insertObject(...) I'm able to call $db->insertid();
user avatar
  • 667
2 votes
Accepted

Save JINPUT to JTable via CLI AND web-backend

You must find an solution to bind the Data from input to the TableObject, thats all. $dataToStore=array('creationdate'=> $input->get('creationdate')); $row = JTable::getInstance('Item','...
user avatar
  • 196
2 votes

Question about JTable::getInstance in libraries/joomla/table/table.php file

Joomla is flexible and relaxed with the physical storage of Table-Classes. The dirty way (I think you do not use a debugger) is to rewrite the following line $paths = self::addIncludePath(); to: ...
user avatar
  • 196
2 votes

Joomla: How to insert $jinput to JTable::store via CLI?

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 ...
user avatar
  • 7,685
2 votes
Accepted

storing id using JTables

Your $data needs to be just column names, not with any values. $data = array('articleId', 'title', 'sharetoken'); and $values dosen't have correct id right now, since your are quoting just pasic ...
user avatar
  • 3,208
2 votes
Accepted

Strange behavior with dates

I looked at the code for this. JDate::dateformat is public, which means ANY code can modify the value. I would start doing a grep/search through my source tree (and any plugins/modules/libraries) to ...
user avatar
2 votes
Accepted

Use JTable to save frontend-data

Let me explain how joomla works imo. Controllers are for creating / executing route and calling model for some work. In controller you have method called save but it's preprocess $_POST aka $data ...
user avatar
  • 522
2 votes
Accepted

Joomla core table names for JTable::getInstance?

Class name is TemplatesTableStyle. But since it's not a core class, you have to register it: JLoader::register('TemplatesTableStyle', JPATH_ADMINISTRATOR . '/components/com_templates/tables/style.php'...
user avatar
  • 8,581
2 votes
Accepted

JTable, new row doesn't get inserted with table->save method

save() calls store(). Store() works like this: If a primary key value is set the row with that primary key value will be updated with the instance property values. If no primary key value is set a new ...
user avatar
  • 374
2 votes

Joomla 3.9 replace zero dates with null on save/checkin (mysql zero date deprecated)

With thanks to @glenn-arkell who pointed me in the right direction, for j3.9 this works to stop Joomla writing '0000-00-00 00:00:00' into the checked_out_time field. For other fields (eg modified and ...
user avatar
  • 51
1 vote
Accepted

Save failed with the following error: Unknown column 'created' in 'field list'

You must have missed something when adapting the files to your table structure. Run a search for created through the files. It could be this line in /administrator/com_banners/tables/banner.php: $...
user avatar
  • 8,581
1 vote

Programmatically update Menu Item in Component

If the menu item already exists then you don't need jtablenested at all - you should just update the fields directly in the database. What you do need is the menu item's id in Joomla's menu table. ...
user avatar
  • 3,134
1 vote

Load from JTable with some null values

May need some more detail on the db structure here. For example, if I understand you correctly that you have defined three fields in the db as 'must be unique,' any database that correctly follows the ...
user avatar
  • 802
1 vote
Accepted

How to use look-up tables in a custom component?

All of the 3 ways (models, JTable, helper class) are legit ways in Joomla to solve your problem. I would probably make a JTable class for your look up table (for CRUD operations) and add models (list ...
user avatar
  • 3,693
1 vote

After upgrade to 3.5: return $row->id (last saved item) does not work

The problem is solved. On Joomla 3.5 the PDO driver does not return an id. This is discussed and will be solved: https://github.com/joomla/joomla-cms/issues/9534
user avatar
  • 667
1 vote

Why is there no rebuild() function call after deleting a usergroup?

The question would be if there is a need to rebuild the structure after a deletion. In my opinion, only new items force a rebuild and usergroup deletion does not require a rebuild. If you find a ...
user avatar
  • 7,415
1 vote

Using tags: JTable::store() returns false

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->...
user avatar
1 vote

A foreign key field not updating as NULL

You should take care of this in JTable only. This part: if ($data['leavepack_id'] == '') $data['leavepack_id'] = NULL; you should insert in JTable::check() like this: public function check(){ ...
user avatar
1 vote

Store data to other table and get the id

The problem is solved. On Joomla 3.5 the PDO driver does not return an id. This is discussed and will be solved: https://github.com/joomla/joomla-cms/issues/9534
user avatar
  • 667

Only top scored, non community-wiki answers of a minimum length are eligible