Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

8

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 think of the table as being like a wrapper around a row to insert. You go through a 3 stage process. bind takes the array of data that comes from your form and ...


6

$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 at lines 268-272 where getInstance begins: public static function getInstance($type, $prefix = 'JTable', $config = array()) { // Sanitize and prepare the ...


4

$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'] = $userid; $maildata['title'] = $title; $maildata['state'] = $state; $row=JTable::...


3

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) ->select($db->quoteName('id')) ->from($db->quoteName('#__users')) ->where($db->quoteName('email') . ' = ' . $db->quote($email))...


3

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 have to use multiple tables and it can happen in many models. If you use JTable you don't have to rewrite SQL in every model just to retrieve or modify a single ...


3

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->getTable(); if(!$table->bind($data)){ $this->setError($this->_db->getErrorMsg()); return false; } if(!$table->store(true)...


3

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.'/models/article.php'; $artmodel = new ContentModelArticle(array('table_path' => $basePath.'/tables')); $db = JFactory::getDbo(); $q = "SELECT * #__content WHERE ...


3

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 binded data to your database. In other words: You are responsible for correlating fields/properties.


2

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 database level, but instead Joomla handles it at application(code) level. If you want to go ahead with Joomla standard way, and also if you are developing ...


2

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 purpose is much more narrow. You will see that most major template developer have created their own framework, this shows there is more work to be done at the ...


2

Solved it :-) Just define $db = JFactory::getDbo(); and after $db->insertObject(...) I'm able to call $db->insertid();


2

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','BestiaTable'); // BIND DATA TO THE TABLE OBJECT!!! $row->bind($dataToStore); $row->check(); // please write an check method which checks the datas before ...


2

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: var_dump($paths = self::addIncludePath()); So you will see the paths where the Table-Class are stored. 3rd-party components tells Joomla where their own ...


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; ...


2

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 string, not a value of id. $values = array($db->quote($this->get('id')), $db->quote($title), $db->quote($token)); So, complete code should look like ...


2

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 look for assignments to it. Looking at the Time difference issue, what I think is that JFactory() is constructing the date two different ways. The first, with ...


2

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 and pass it to model, $controller->getModel()->save(). For me it's better to call model and pass data and use multiple JTable, it's better for further use ...


2

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'); or include the whole com_templates/tables folder: JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables'); Then this should work:...


1

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: $this->created = JFactory::getDate()->toSql(); Also, look at the class of your component's model. Based on your update, and given the advice I gave you (i....


1

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. You should probably store it when you create the menu item the first time around as your menu item presumably corresponds to something in your custom component. ...


1

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 SQL specification will not let you put a null in any of those fields. (Some dbs allow it, but I'm not sure I'd depend upon that condition to continue.) It ...


1

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 and item) and the views and controllers for it. So you can modify the lookup data in your backend and if you add some more special fields to your table you ...


1

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


1

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 case where it does work as expected, it is a bug. You can submit a Pull Request to fix the issue to https://github.com/joomla/joomla-cms.


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 ...


1

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(){ if ($this->leavepack_id == '') $this->leavepack_id = NULL; return parent::check(); } and then override store function like this: public function ...


1

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


1

To get the last insertId use: $newID = $row->insertId(); Here is the documentation You have to call it just after $store = $row->store();


1

From my understanding you should be using multiple JTable instances in your model when you have multiple tables. Take a look at these models in the CMS they might give you some direction for how to set up your model. https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_installer/models/manage.php https://github.com/joomla/joomla-...


1

Your question is not entirely correct. Your submit button is invoking a method save() on a controller. You can find out the correct controller by inspecting the task field of the form <input name="task" value="controllername.save" /> or it could be in a parameter of the form's action attribute i.e. <form action="index.php?option=com_component&...


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