Skip to main content
5 votes
Accepted

How to call a model method from a system plugin?

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'); /...
Piero Marsilio's user avatar
4 votes

How to call a model method from a system plugin?

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 ...
Amit Ray's user avatar
  • 237
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 ...
Artur Stępień's user avatar
3 votes

Insert value to custom field using getForm (setFieldAttribute)

Mea culpa, I had to add the name of the group: $form->setFieldAttribute('test', 'country', 'US', 'personal');
MyFault's user avatar
  • 677
3 votes
Accepted

Check a form field for duplicates before saving

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' =&...
Nagarjun's user avatar
  • 2,991
2 votes

How can I use a model of other component in my component?

You may get an error like this: Call to a member function load() on boolean That mean you need to add JTable::addIncludePath also Admin Model: function getModelAdmin($component, $name = 'Custom', $...
Mansour Alnasser's user avatar
2 votes

What is the proper way to handle models that use other models in MVC?

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 ...
AndyGaskell's user avatar
2 votes
Accepted

Problems with ajax call in component

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 ...
Anibal's user avatar
  • 7,435
2 votes
Accepted

Joomla getting items via model wrong data type

It is a json encoded string. $images = json_decode($item->images);
David Hayes's user avatar
2 votes

Component getList cache not loading/saving

In your component controller, check the display function: public function display($cachable = false, $urlparams = false) { //... parent::display($cachable, $safeurlparams); return $...
Dennis Heiden's user avatar
2 votes

Sharing a model between two views in a component

OK, comments are not the easiest place to talk in details (too short, too easy to misinterpret) so I'll post this here. It may be a bit wide-ranging and high-concept at first b/c of the lack of detail ...
Arlen's user avatar
  • 802
2 votes
Accepted

How to use JDate / HTMLHelper inside model?

Joomla\CMS\Date\Date doesn't have $date property or get() method. Use $date->format($format) to format the date where $format is the date format. To format a date using Joomla\CMS\HTML\HTMLHelper, ...
Sharky's user avatar
  • 11.3k
2 votes

Dynamically removing single JForm option

Another option could be to place the two versions of the field in separate .xml files in your /forms folder and then decide which one to load. If ($option == 1) { $form->loadFile('...
Irata's user avatar
  • 3,927
2 votes

Dynamically removing single JForm option

So this is what I've done: protected function preprocessForm(JForm $form, $data, $group = '') { $app = JFactory::getApplication(); ... if ($app->isClient('site')) { // ...
Mike's user avatar
  • 351
2 votes

Dynamically removing single JForm option

The small problem with your question is that <option> is not a field attribute but an element in XML, so you cannot set or remove that using methods for field attributes. You can remove however ...
Zollie's user avatar
  • 2,936
2 votes
Accepted

Redirect controller function on load, what function do I need to use?

Many years ago I had the same question: "where should I put my own code in Joomla?". It was very frustrating at that time for me too and Joomla has a long learning curve, comparing to ...
Zollie's user avatar
  • 2,936
2 votes
Accepted

Model not found when from a controller

MycomponentController class is missing the class prefix. It should be - namespace Example\Mycomponent\Libraries\Controller; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\MVC\Factory\...
Jumbo's user avatar
  • 175
1 vote
Accepted

I want to display a form with the data added already

There is a method $form->setProperty() which does this.
DeesreX's user avatar
  • 87
1 vote
Accepted

How do I save Repeatable data in my component model?

Please note that the original repeatable field is deprecated in favor of the subform field. I think you need to deal with the data before saving it to the database. What I did for a single text field ...
Bakual's user avatar
  • 5,582
1 vote

Model not found when from a controller

As far I am aware, feel free to correct me as I haven't played with Joomla 4 too much, the class naming conventions for controllers, models and views you need to use for Joomla to automatically ...
Irata's user avatar
  • 3,927
1 vote
Accepted

Bring featured articles to the front of the articles retrieved by ArticlesModel

Order by featured column and use descending direction: $model->setState('list.ordering', 'a.featured'); $model->setState('list.direction', 'DESC');
Sharky's user avatar
  • 11.3k
1 vote
Accepted

Add fields to the articles retrieved by ArticlesModel

Normally fields are added by the Fields plugin. You can trigger onContentPrepare event to run this and other content plugins: JFactory::getApplication()->triggerEvent('onContentPrepare', ['...
Sharky's user avatar
  • 11.3k
1 vote
Accepted

How to remember User State settings when returnng to a Site View?

It doesn't look like you are including the menu Itemid in your redirect which is why your URL is changing. Add another hidden field with the value of your current Itemid. Your redirect code is fine ...
Terry Carter's user avatar
  • 1,812
1 vote
Accepted

Why are methods randomly placed in models as well as controllers in Joomla

The comment from @mickmackusa is essentially correct, but there's some context missing, perhaps, from your question that makes me wonder if you're not asking a wider question. There are wide variety ...
Arlen's user avatar
  • 802
1 vote
Accepted

Adding multiple Models into a component.

Okey this was a stupid question, I just needed to add: var_dump ($model->getFck());
ValRob's user avatar
  • 123
1 vote
Accepted

Is it possible to check if a method or function exists in the component controller?

I never figured out how to use $this, but it was pretty straightforward otherwise. This checks to see if the add method exists in the Article controller. $ToolsClass = 'ContentControllerArticle'; $...
GDP's user avatar
  • 7,715
1 vote
Accepted

Component in module. addModelPath doesn't seem to work

Loading a model: JLoader::import('joomla.application.component.model'); JLoader::import( 'user', JPATH_SITE . DS . 'components' . DS . 'com_helloworld' . DS . 'models' ); $user_model = JModelLegacy::...
Dennis Heiden's user avatar
1 vote

Custom dynamic fields - SimpleXMLElement in model and data info fields

My fault. Wrong order. Corectly is: 1. First - create form and transform to SimpleXMLElement $formXml = new SimpleXMLElement(file_get_contents(JPATH_COMPONENT.'path to xml file')); Add ...
K.I.D.'s user avatar
  • 21
1 vote
Accepted

Can a model display itself within the view of a different model?

Not by default, no. The model and the view basically don't talk to each other at all, all interaction between them is handled by the controllers. The reason the model is attached to the view is ...
Bathmat's user avatar
  • 492
1 vote

How to get xml form values in Joomla 2.x?

You can add a parameter in the menu item and to obtain the value_field. You cannot directly achieve that but yes you can concat the 2 columns and pass the value in key_field in xml and then explode in ...
Liz.'s user avatar
  • 1,385

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