?
avatar JustPlainHigh
JustPlainHigh
9 Aug 2015

Steps to reproduce the issue

Apologies, I am new to component creation so I'm probably going to come across as stupid... This error is very application specific. I am creating a component that tracks vehicles and created:

  • ArmsControllerVehicleModel extends JControllerForm
  • ArmsModelVehicleModel extends JModelAdmin

And so on. Everything was working great right up until I wanted to add a filter to the vehiclemodels -> view -> default.php

From var_dump($this) in the view default.php for vehiclemodel, I managed to pick up that the filter form for the view was NULL (there was a correctly named .xml) and the 'option' for the model was 'com_testmodelvehicles' instead of 'com_test'.

Expected result

The view should have displayed the filter.

Actual result

Call to a member function getGroup() on a non-object bar.php because the option was incorrect and/or no filter xml was found for the model.

Once I changed all my class named from Model to Mdel, everything worked as expected. I believe the error was caused by the legitimate use of 'Model' in the class name and how class names are parsed. But, like I said, it is a very specific case.

System information (as much as possible)

Joomla! 3.4.3

Additional comments

Thanks for the hard work and great system!

avatar JustPlainHigh JustPlainHigh - open - 9 Aug 2015
avatar Bakual
Bakual - comment - 9 Aug 2015

Please use our Google Group for support requests. (https://groups.google.com/forum/#!forum/joomla-dev-general)

This is the issue tracker for Joomla core.

avatar Bakual Bakual - change - 9 Aug 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-08-09 07:45:09
Closed_By Bakual
avatar Bakual Bakual - close - 9 Aug 2015
avatar Bakual Bakual - close - 9 Aug 2015
avatar JustPlainHigh
JustPlainHigh - comment - 9 Aug 2015

It is not a support request. I got everything to work but only if I change the class names to VehicleMdel instead of VehicleModel. This is a problem with how Joomla core processes model names that contain the legitimate use of the word 'Model' like 'Vehicle Model' or 'Bikini Model'.

As mentioned, the problem is very case specific. Was just pointing it out. Again... not a request for support ;-)

avatar Bakual Bakual - change - 9 Aug 2015
Status Closed New
Closed_Date 2015-08-09 07:45:08
Closed_By Bakual
avatar Bakual Bakual - reopen - 9 Aug 2015
avatar Bakual Bakual - reopen - 9 Aug 2015
avatar Bakual
Bakual - comment - 9 Aug 2015

I can reopen it.

Are you using a view class named "VehicleModel" then? Because by default our MVC will try to guess the model name based on the current controller name and the view name. So usually you would have a model class named "ComponentModelView", while "ComponentModel" is the "model prefix". You got a part to much in there somehow anyway.

avatar brianteeman
brianteeman - comment - 9 Aug 2015

Shouldnt it be VehicleModelModel because Vehicle and model are the name
and the final Model the MVC

On 9 August 2015 at 13:15, Thomas Hunziker notifications@github.com wrote:

I can reopen it.

Are you using a class named "VehicleModel" then? Because by default our
MVC will try to guess the model name based on the current controller name
and the view name. So usually you would have a model class named
"ComponentModelView", while "ComponentModel" is the "model prefix". You got
a part to much in there somehow anyway.


Reply to this email directly or view it on GitHub
#7665 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar JustPlainHigh
JustPlainHigh - comment - 9 Aug 2015

My component name is 'Arms' (com_arms) and the:

ArmsModelVehicleModel extends JModelAdmin
was the model that caused the problem.

I noticed it trying to get the list view to display a filter. The second 'Model' in the model name seems to break something because the Joomla core picked up the incorrect 'option' (should have been 'com_arms', but was 'com_armsmodelvehicles') when I did a var_dump in the view. Core could then not find the filter.xml for the view despite the file being correctly labelled. That then caused the error 'Call to a member function getGroup() on a non-object bar.php'.

It cleared up as soon as I changed everything that contained 'vehiclemodel' to 'vehiclemdel'.

I experienced no problems with any of the other models.

avatar JustPlainHigh
JustPlainHigh - comment - 9 Aug 2015

@brianteeman As I said earlier, I'm new to Joomla component development... Perfectly prepared to accept this as my own daftness and have the report closed ;-)

avatar Bakual
Bakual - comment - 9 Aug 2015

What is the name of the view? Because as explained the model name consist by default of three parts, and yours is four (Arms, Model, Vehicle, Model). If the viewname is indeed "vehiclemodel", then the model should be named "ArmsModelVehiclemodel" instead.
I'm not saying this is the source of the fault (probably it isn't), but it certainly is something which doesn't follow the norm.

avatar JustPlainHigh
JustPlainHigh - comment - 9 Aug 2015

The view name was

class ArmsViewVehicleModels extends JViewLegacy

The strangeness is all the other views and models that follow a similar pattern work:

class ArmsViewVehicleManufacturers extends JViewLegacy
class ArmsModelVehicleManufacturers extends JModelList
class ArmsModelVehicleManufacturer extends JModelAdmin

And I'm going to fess up here and say I totally cheated by using a component builder ^_^. But I have taken a note of the naming convention you pointed out - thanks!

I have the component package with just the 'vehicle model' class if you'd like to have a look.

avatar Bakual
Bakual - comment - 9 Aug 2015

Just try to lowercase the last bit, making it a three part name. It will reduce potential issues in future for sure and maybe even solves the issue at hand.

avatar dgt41
dgt41 - comment - 9 Aug 2015

I thought this was fixed already: https://groups.google.com/forum/#!topic/joomla-dev-general/IWVqNQYjSAY

I am quoting Don’s solution here, that worked for me back then:
To fix it, you need to set the $option and the $name parameters in your model.

class TestModelModel extends JModelAdmin
{
    protected $text_prefix = 'COM_TEST;
    protected $option = 'com_test';
    protected $name = 'model';
avatar JustPlainHigh
JustPlainHigh - comment - 9 Aug 2015

The lower case 'model' resolves the list view issue, but it does not appear to resolve the individual edit view problem - although I don't know why that is. I have attached screen shots of both 'Vehiclemodel' (warns that it can't find component, although it saves the item fine) and 'Vehiclemdel' (works without issue).

screenshot-arms2 2015-08-09 15-41-01
screenshot-arms2 2015-08-09 15-39-40

avatar Bakual
Bakual - comment - 9 Aug 2015

I'd say raise it on the Google Group I mentioned earlier with all the error messages you get.
I'm quite sure it can be solved in code.
If not and there is indeed an issue in core, you can always create a new issue.

avatar Bakual Bakual - change - 9 Aug 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-08-09 14:05:57
Closed_By Bakual
avatar Bakual Bakual - close - 9 Aug 2015
avatar Bakual Bakual - close - 9 Aug 2015
avatar JustPlainHigh
JustPlainHigh - comment - 9 Aug 2015

@dgt41 Thanks for that code snippet - will be sure to use that fix if I face this situation again. Otherwise, everything works fine with Mdel and not Model. Going ahead with that for now. Thanks!

Add a Comment

Login with GitHub to post a comment