Start Online Training

Get access to all our video classes and support. That's 1818 training sessions in Joomla, Drupal, WordPress, Coding and SEO.
Prices start only at only 25 USD per month

Testimonials

Testimonials OSTrainingYou are the nicest most accommodating group of people that I have ever come across. That is why I love OSTraining."

~ Corinne

 

Start a FREE 7 day trial! Get training videos and books, plus expert support:  

TOPIC: Error on calling model from another component

Error on calling model from another component 4 months 6 days ago #84704

Hi all,

i'm developing a web application currently over Joomla 2.5.16, doing my self components, modules and plugins to avoid third party dependencies.

The development began over a AppServ with PHP 5.2 and it was just entirely transferred to a PHP 5.3 server. Before the move, all works fine, but once moved to the new server, I´m finding some problems in PHP code execution, returning the next error:
Fatal error: Call to a member function getMainFilter() on a non-object in /home/myhost/www/myproject/components/com_qorders/views/order/view.html.php on line 41

The code relative to this error is the next one:
<?php
 
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
jimport( 'joomla.application.component.model'); 
 
JLoader::import( 'QGroup', JPATH_ROOT . DS . 'components' . DS . 'com_qgroup' . DS . 'models' );
 
class QOrdersViewOrder extends JView
{
	function display($tpl = null)
	{
		$model = $this->getModel();
 
		// Here comes the order info
		$orderInfo = $model->getOrderInfo();
		$this->assignRef( 'orderInfo', $orderInfo );
 
		// Now get main filter
		$QGroupModel = JModel::getInstance( 'QGroup', 'QGroupModel' );
		$mainFilter = $QGroupModel->getMainFilter();
		$this->assignRef( 'mainFilter ', $mainFilter );
 
// And so on....

What I'm doing is using a model from another component to get an array that must be used at the current view, but when I call a method from the external model, application throw that error on this line:
$mainFilter = $QGroupModel->getMainFilter();

I´ve looking for issues over PHP 5.3 but nothing found (although it does not mean they do not exist...). Application works fine over PHP 5.2 at the first server, but no way to get it working on the new server with PHP 5.3.

Any idea about what is happening or what I'm forgotting?

Thanks in advance.
Last Edit: 4 months 6 days ago by 2ksystems.
Please become a member of OSTraining to reply to this post.

Error on calling model from another component 4 months 6 days ago #84723

Well... I will answer myself:

The issue was related to JLoader::import, that seems to don't be working correctly. I've used JModel::addIncludePath instead and all works OK now.
JModel::addIncludePath(JPATH_ROOT.DS.'components'.DS.'com_qgroup'.DS.'models', 'QGroup');

Thanks anyway and hope this helps :)
Please become a member of OSTraining to reply to this post.

Error on calling model from another component 4 months 6 days ago #84724

  • Valentin
  • Valentin's Avatar
  • OFFLINE
  • Posts: 3273
  • Thank you received: 63
Hi 2ksystems!

Is possible to have access to your Joomla backend to see if we are missing something? - please do to: This email address is being protected from spambots. You need JavaScript enabled to view it. - add the url of this forum post in the message

Looking forward to help you

Kind regards,
Valentín
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Error on calling model from another component 4 months 6 days ago #84725

  • Valentin
  • Valentin's Avatar
  • OFFLINE
  • Posts: 3273
  • Thank you received: 63
Looks like we replied at same time, funny.

I'm glad you figure out by yourself.
Something important that you may need in future if you upgrade to Joomla 3.x this project, is the DS constant won't work. In Joomla 2.5.x should be fine.

Keep your questions coming

Kind regards,
Valentín
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Error on calling model from another component 4 months 6 days ago #84726

Thanks anyway Valentin :)

I don't know the reason of the failure since I was unable to find info about this at the Joomla 2.5 API documentation. I will investigate it when I have time to do it and post the answer here.

Thanks for the Joomla 3.x tip!

Kind regards,
2KSystems
Please become a member of OSTraining to reply to this post.

Error on calling model from another component 4 months 6 days ago #84729

  • Valentin
  • Valentin's Avatar
  • OFFLINE
  • Posts: 3273
  • Thank you received: 63
You're welcome, 2KSystems!

Have a nice day.

Kind regards,
Valentín
Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

 

Start a FREE 7 day trial! Get training videos and books, plus expert support: