Hot answers tagged

16

You can import com_content models into the controller using addIncludePath() method: JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_content/models', 'ContentModel'); addIncludePath() method adds a directory where JModelLegacy should search for models. You may either pass a string or an array of directories as the first parameter. As the second ...


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


7

You may need to import the table classes also. Try calling JTable::addIncludePath(/path/to/other/component/tables); to bring them in.


6

You can see it in action in the main controllers of the core components. For example ContentController of Content component. // Check for edit form. if ($vName == 'form' && !$this->checkEditId('com_content.edit.article', $id)) { // Somehow the person just went to the form - we don't allow that. return JError::raiseError(403, JText::...


4

I would think you need to catch the output from your module using a component. You can use JForm to output the form in your module, and then have hidden inputs like <form action="index.php" method="POST" name="yourform"> <input type="hidden" value="com_yourcomponent" name="option"/> <input type="hidden" value="yourview" name="view"/> <...


4

Try to add an additional path where to look for forms before your call to $model->get('Form'). JForm::addFormPath(YOUR_COMPONENT_FORMS_PATH); You will need it because getForm calls loadForm (declared on the ancestor class JModelForm) which, before getting the form instance, uses this JForm::addFormPath(JPATH_COMPONENT . '/models/forms'); JForm::...


4

Initially I figured the best would be to use the controller method save(), which I finally got working like this: $path = JPATH_ADMINISTRATOR . '/components/com_anycomponent; JLoader::register('AnycomponentControllerAnyController', $path . '/controllers/anycontroller.php'); $controller = AnycomponentControllerAnyController::getInstance('Anycomponent'); $...


4

This will work with ease in Joomla 3.x //load model JModelLegacy::addIncludePath(JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_foo' . DIRECTORY_SEPARATOR . 'models'); //get instance of model class, where class name will be fooModelBar $model = JModelLegacy::getInstance('bar', 'fooModel'); //call model method $baz = $model-&...


4

To call a model from anywhere inside Joomla you can use this method //Load the Joomla Model framework jimport('joomla.application.component.model'); //Load com_foo's foobar model. Remember the file name should be foobar.php inside the models folder JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_foo/models', 'FooModelBar'); //Get Instance of ...


3

The best place is your table class before storing data. For example below code in store function of table class. public function store ($updateNulls = false) { if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_(...


3

This docs page should help you with this: https://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core NOTE: this does not work on its own, instead you need to create a plugin for your overridden controller: There may be times when you need to override the Joomla! MVC Component to add new functionality or to completely customise the ...


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

You're right the submit with a module is a bit more difficult because form submits have to go to a URL. It is messier to have to write a component just to accept the input from the module too. Because of this issue, in Joomla 3 is Matt Thomas wrote a component called com_ajax. Com_Ajax is a component that is designed to assist modules with doing things ...


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.


3

Using state in the select statement allows external extensions to use your method individually and to get different sets of data from it. A good example is mod_articles_news module helper which sets the fields for selection from the Articles Model: // Get an instance of the generic articles model $model = JModelLegacy::getInstance('Articles', 'ContentModel'...


3

You can just execute it in the same way than a simple query. db->setQuery($my_big_query); $row = $db->loadObject(); Of course, it would be very difficult to translate the SQL statement to build it with Query API $query->select(...)->from(...). It is better to just handle the query with a big string, avoiding PHP performance bottlenecks. ...


3

There is no standard way to integrate 3rd party component's model. Every developer implements its own way. After integrating 50+ plugins in AutoTweetNG and Joocial, the method that usually works is to check extension's modules or plugins, looking for the way the model is integrated. For instance, VirtueMart works in this way: if (!class_exists('...


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


2

The filter fields list is a configuration option for ordering purposes, it's a white list of field names that are permitted for usage in queries, so apparently you can use a.field1 for instance as query specific. So in your view, you write something like this: <?php echo JHtml::_('grid.sort', 'COM_MYCOMPONENT_NAME', 'name', $listDirn, $listOrder); ?> ...


2

I think you have to include the paths both for model and table: JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_main/models', 'ByteitBookingModel'); $modelTU = JModelLegacy::getInstance('TimeUnit', 'ByteitBookingModel'); $modelTU->addTablePath(JPATH_ADMINISTRATOR . '/components/com_main/tables');


2

I do not know if this is possible using SQL, but you can get such result using PHP: $byCategory = array(); foreach ($items as $item) { if (empty($byCategory[$item->category_title])) { $byCategory[$item->category_title] = array(); } $byCategory[$item->category_title][] = $item; } $byCategory array will have the data ...


2

Try the parent from your get function public function getMyInfo($pk = null) { $myItem = parent::getItem($pk); echo $myItem->myfieldname; . . .


2

Database driver will add the result back to the Table after saving. So, something like next should work: $table = $this->getTable(); if ($table->save($data) === true) { return $table->id; } else { return false; }


2

You could map array to object. $object = Joomla\Utilities\ArrayHelper::toObject($array, 'JObject'); Your code would become $data = (array)JFactory::getApplication()->getUserState('com_mycomp.edit.profile.data', array()); $data = Joomla\Utilities\ArrayHelper::toObject($data, 'JObject'); //Do further validation on $data and adjust the required values ...


2

I don't see where in your code you are outputting the object that you mentioned, normally the query produced by getListQuery should result in an array. I'm presuming that object is an example of one that might be contained within the array? If so then I would replace your group concat as follows $query->select('GROUP_CONCAT(cast(concat(tma.filename,\'|\...


2

I think $mydata = $this->get('MyData'); is the best way to call model's functions if you don't need to pass any argument. Model's function are already available in the MVC view logic and using the second method to reload the model feels redundant to me. Usually I write my component's model functions using only arguments passed trough GET or POST and ...


2

Mea culpa, I had to add the name of the group: $form->setFieldAttribute('test', 'country', 'US', 'personal');


2

There are many software design / architecture patterns and the is a good overview at https://en.wikipedia.org/wiki/Architectural_pattern From your description, it sounds like having a single joomla component with a model, view(s) and control will work ok. It is hard to say what is best, but perhaps your might have the following... Models actor (person or ...


2

By default, each http request is independent. You have to send all parameters again in each call. Alternatively, if your client can keep session cookies, then you can store server-side variables in user session to keep an state between http requests. $session = JFactory::getSession(); $session->set('myId', $myId); ... $session = JFactory::getSession(); $...


2

In your component controller, check the display function: public function display($cachable = false, $urlparams = false) { //... parent::display($cachable, $safeurlparams); return $this; } Change it to: parent::display(true, $safeurlparams); And test again.


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