get Model not returning a model

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
User avatar
epeeist
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Wed Oct 05, 2005 7:28 pm
Location: Manchester, UK

get Model not returning a model

Post by epeeist » Wed Feb 25, 2009 9:44 am

I am refactoring a component I produced for Joomla! 1.0 for Joomla! 1.5. I have the following code fragment:

Code: Select all

class ResultsViewOverall extends JView {
  function display($tpl = null) {
    $model =& $this->getModel();

    $results = $model->getResults($event, $year, $sort, $number);
This dies on the last line with the error "Call to a member function getResults() on a non-object". When I investigate more closely $model is actually null. I am baffled as to why the getModel method doesn't return me an object. A dump of $this shows no value for the default model.

Any ideas what I am doing wrong?

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: get Model not returning a model

Post by dam-man » Wed Feb 25, 2009 10:31 am

When getting data from a model, the model needs to pass data back.
This can be set in your model, see example:

Connecting the model from the view.html.php file:

Code: Select all

## Connecting the desired model
$model	=& $this->getModel();
## $makes will be the array List is a function in the model
$makes	=& $this->get('List');
In the model I have the following function "list" :

Code: Select all

   function getList()
   {
      if (empty($this->_data))
      {
         $db = JFactory::getDBO();

		## Making the query for showing all the cars in list function
		$sql = "SELECT * FROM table ORDER BY id";
		 
         $db->setQuery($sql);
         $this->data = $db->loadObjectList();
      }
      return $this->data;
   }
It's returning data as you can see, this data will be availeble in the $makes variable. This will be passed to the default.php in the tmpl folder

Hope this helps?
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards

User avatar
epeeist
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Wed Oct 05, 2005 7:28 pm
Location: Manchester, UK

Re: get Model not returning a model

Post by epeeist » Wed Feb 25, 2009 11:21 am

dam-man wrote: Hope this helps?
I am afraid not:

To go right back to the beginning. In my controller I have:

Code: Select all

class ResultsController extends JController {
  function display() {
    parent::display();
  }

  function overall() {
    JRequest::setVar('view', 'overall');
    parent::display();
  }
The first is obviously the default. The view for this looks like:

Code: Select all

class ResultsViewResults extends JView {
  function display($tpl = null) {
    $model =& $this->getModel();

    $lowestYear = $model->yearMin();
    $highestYear = $model->yearMax();
If I do a print_r on both $this and $model then I get appropriate information.

In my "overall" view I have

Code: Select all

class ResultsViewOverall extends JView {
  function display($tpl = null) {
    $model =& $this->getModel();
But a print_r on $this shows no default model and a print_r on $model shows it to be null. Given that they look exactly the same I am baffled as to what I am doing wrong >:(

coolbung
Joomla! Guru
Joomla! Guru
Posts: 552
Joined: Sat Nov 11, 2006 5:03 am
Contact:

Re: get Model not returning a model

Post by coolbung » Wed Feb 25, 2009 6:04 pm

epeeist,

What Robert is trying to say is that

Code: Select all

$model   =& $this->getModel();
$data = $model->getResults();
is not the preferred way of doing things. It will always fail.

You should do it the following way

Code: Select all

$data =& $this->get('Results');
Of course assuming that your model is having a method called 'getResults'
Ashwin K. Date - Follow @coolbung @tekdinet @techjoomla @jugpune
Joomla! Extensions & Training - www.techjoomla.com

secteur
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 146
Joined: Tue Nov 08, 2005 9:32 am
Location: Malaysia

Re: get Model not returning a model

Post by secteur » Thu Feb 26, 2009 11:19 am

Hi,

could it be that your model is called ResultsModelResults and you dont have one called ResultsModelOverall?

The view looks for the default model by using:
ComponentnameModelViewname

Could be the reason why your model is not found... In which case you need to add the Results model to the view in the controller like this (I'm guessing it s in your overall function, right?):

Code: Select all

class ResultsController extends JController {
  function overall() {
    $view = $this->getView( 'overall', 'html' );
    $view->setModel( $this->getModel( 'results', 'resultsModel' ), true ); 
    $view->display();
  }
Hope this helps

krombit
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed May 14, 2008 9:23 pm

Re: get Model not returning a model

Post by krombit » Fri Mar 06, 2009 3:25 am

A similar experience for me where I get a fatal error when trying to access datasets from a different 'model'
Fatal error: Call to a member function getMenu() on a non-object in ...\views\fred\view.html.php

In my understanding that the model is used to interact with the repository (http://forum.joomla.org/viewtopic.php?f=231&t=315198), eg fetch data from a table(s) and present it back to the caller as a list object. It would make sense that there would be datasets that would be required by numerous views and would be accessible by specifying the model for such sources.

Code: Select all

class LunchModelBetty extends JModel
  function...
  function...
  function getMenu() ...
So in my view I try to retrieve a list by calling a function elsewhere

Code: Select all

class LunchViewFred extends JView
  $model =& $this->getModel('Betty');
  $choices = $model->getMenu();
However this unfortunately results in the fatal error.

So, how does one access datasets defined elsewhere?

coolbung
Joomla! Guru
Joomla! Guru
Posts: 552
Joined: Sat Nov 11, 2006 5:03 am
Contact:

Re: get Model not returning a model

Post by coolbung » Fri Mar 06, 2009 5:21 am

Seems like you cannot access one model from another view.
What you can do is include some common functions in a helper file.
Ashwin K. Date - Follow @coolbung @tekdinet @techjoomla @jugpune
Joomla! Extensions & Training - www.techjoomla.com

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: get Model not returning a model

Post by dam-man » Fri Mar 06, 2009 12:54 pm

By defining the model you access the model from another view..
For example:

I have the code below in view "test", it will automatically connects the test.php model.
This is because I dn't define a model. (see my bold text below)

## Connecting the desired model
$model =& $this->getModel();
## $makes will be the array List is a function in the model
$makes =& $this->get('List');

Now I am still in the "test" view. But I want to connect model "damman"
As you can see in my bold text, I am now wanted to be connected with the damman model

## Connecting the desired model
$model =& $this->getModel('damman');
## $makes will be the array List is a function in the model
$makes =& $this->get('List');

It works with me..
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards

User avatar
Hackwar
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3788
Joined: Fri Sep 16, 2005 8:41 pm
Location: NRW - Germany
Contact:

Re: get Model not returning a model

Post by Hackwar » Fri Mar 06, 2009 12:59 pm

To get a model in the view that is named differently than the view itself, you need to set that model in the controller, not in the view.
god doesn't play dice with the universe. not after that drunken night with the devil where he lost classical mechanics in a game of craps.

Since the creation of the Internet, the Earth's rotation has been fueled, primarily, by the collective spinning of English teachers in their graves.

coolbung
Joomla! Guru
Joomla! Guru
Posts: 552
Joined: Sat Nov 11, 2006 5:03 am
Contact:

Re: get Model not returning a model

Post by coolbung » Sat Mar 07, 2009 10:58 am

In that case the entire view will get that model, right? Which is what epeeist dosent want..
So basically, if you need a common function, it's best declared in a helper file?
Ashwin K. Date - Follow @coolbung @tekdinet @techjoomla @jugpune
Joomla! Extensions & Training - www.techjoomla.com

User avatar
Hackwar
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3788
Joined: Fri Sep 16, 2005 8:41 pm
Location: NRW - Germany
Contact:

Re: get Model not returning a model

Post by Hackwar » Sat Mar 07, 2009 12:17 pm

no, you can use as many models as you want in a view, you only need to name them differently in the controller.

$this->setModel($model, 'model1') <== in the controller

$model = $this->getModel('model1') <== in the view
god doesn't play dice with the universe. not after that drunken night with the devil where he lost classical mechanics in a game of craps.

Since the creation of the Internet, the Earth's rotation has been fueled, primarily, by the collective spinning of English teachers in their graves.

coolbung
Joomla! Guru
Joomla! Guru
Posts: 552
Joined: Sat Nov 11, 2006 5:03 am
Contact:

Re: get Model not returning a model

Post by coolbung » Sat Mar 07, 2009 5:21 pm

Ok,
I'm gonna try that next time.

Thanks Hackwar
Ashwin K. Date - Follow @coolbung @tekdinet @techjoomla @jugpune
Joomla! Extensions & Training - www.techjoomla.com

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: get Model not returning a model

Post by dam-man » Sat Mar 07, 2009 7:23 pm

nice information, why is this not in the documentation? ;)
the way i did is also working in my component.
But if we do it like the Joomla! devs say, it's also good.
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards

User avatar
juanparati
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 123
Joined: Thu Nov 08, 2007 6:00 pm
Location: Aarhus (Denmark)

Re: get Model not returning a model

Post by juanparati » Sat Mar 14, 2009 4:32 pm

Sometimes Joomla framework do not simplificate some tasks.

Why don't use:

Code: Select all

require_once(JPATH_COMPONENT.DS.'models'.DS.'myothermodel.php');
$model=new ComponentModelmyothermodel;
Is it ok to do it in this way when you want to load other model? ???
From the code to the reality!

devlabs
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Fri Jan 23, 2009 10:39 pm

Re: get Model not returning a model

Post by devlabs » Tue May 12, 2009 10:38 pm

I don't understand you people. I have spent a few hours trying to do a simple thing - to include function from one model/view to another model/view, I think this is very important part and everyone should use it in developing but whatever.

Great thanks to juanparati cause this is the only code that worked for me:
require_once(JPATH_COMPONENT.DS.'models'.DS.'myothermodel.php');
$model=new ComponentModelmyothermodel;





Exmple of dam-man:
## Connecting the desired model
$model =& $this->getModel('damman');
## $makes will be the array List is a function in the model
$makes =& $this->get('List');
this doesn't work, when people are saying that it doesn't work it means that it doesn't work.
Why it works on your side? - I think you include some global variables or something else but without them it doens't work, so please include hole peace of the code of your view.html.php


Hackwar:
$this->setModel($model, 'model1') <== in the controller

$model = $this->getModel('model1') <== in the view
the same thing, this doesn't work at all I get an error of missing getModel function and so on. Include full peace of code of controller and view

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: get Model not returning a model

Post by ianmac » Tue May 12, 2009 11:29 pm

devlabs wrote:I don't understand you people. I have spent a few hours trying to do a simple thing - to include function from one model/view to another model/view, I think this is very important part and everyone should use it in developing but whatever.

Great thanks to juanparati cause this is the only code that worked for me:
require_once(JPATH_COMPONENT.DS.'models'.DS.'myothermodel.php');
$model=new ComponentModelmyothermodel;





Exmple of dam-man:
## Connecting the desired model
$model =& $this->getModel('damman');
## $makes will be the array List is a function in the model
$makes =& $this->get('List');
this doesn't work, when people are saying that it doesn't work it means that it doesn't work.
Why it works on your side? - I think you include some global variables or something else but without them it doens't work, so please include hole peace of the code of your view.html.php


Hackwar:
$this->setModel($model, 'model1') <== in the controller

$model = $this->getModel('model1') <== in the view
the same thing, this doesn't work at all I get an error of missing getModel function and so on. Include full peace of code of controller and view
In your controller:

$model1 = &$this->getModel('Model1Name', 'ModelPrefix');
// will load ModelPrefixModelModel1Name from file model1name.php in models directory
$model2 = &$this->getModel('Model2Name', 'ModelPrefix');
// will load ModelPrefixModelModel2Name

$view = &$this->getView($viewName, $viewType, $viewPrefix);
$view->setModel($model1, true); // true makes this the default model
$view->setModel($model2);
$view->display();

In your view:
//invoke get methods on model1 (the default model):
$data = &$this->get('data');
$pagination = &$this->get('pagination');

// get model 2:
$model2 = &$this->getModel('Model2Name');

// we can also get model 1 if we want:
$model1 = &$this->getModel();

Hope that helps.

Ian

devlabs
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Fri Jan 23, 2009 10:39 pm

Re: get Model not returning a model

Post by devlabs » Wed May 13, 2009 2:40 pm

k will try.


to use:
$table->set('id', $id);
I need that id be an int variable


but by default:
$id = JRequest::getVar('id', 0, '', 'array');
it returns an array
id: 0=>'1'


this will cause an error:
$id = JRequest::getVar('id', 0, '', 'int');

what to do?


***** Manual signatures are NOT allowed ********** Manual signatures are NOT allowed *****

I have found next solution but I think there should be a better way to handle it:
===============================
$id = JRequest::getVar('id', 0, '', 'array');
foreach ($id as $key => $value) {
$id=$value;
}
===============================

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: get Model not returning a model

Post by ianmac » Wed May 13, 2009 7:29 pm

devlabs wrote:k will try.


to use:
$table->set('id', $id);
I need that id be an int variable


but by default:
$id = JRequest::getVar('id', 0, '', 'array');
it returns an array
id: 0=>'1'


this will cause an error:
$id = JRequest::getVar('id', 0, '', 'int');

what to do?


***** Manual signatures are NOT allowed ********** Manual signatures are NOT allowed *****

I have found next solution but I think there should be a better way to handle it:
===============================
$id = JRequest::getVar('id', 0, '', 'array');
foreach ($id as $key => $value) {
$id=$value;
}
===============================
If getVar wants to return an array, that means that you have more than one form element with the name id in your form. Try removing the extra ones.

The problem you are experiencing is directly related to what you have in your form. Can't really help you without knowing what elements with name id you have in your form.

Ian

bumslayer
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Mon Jun 29, 2009 8:25 am

Re: get Model not returning a model

Post by bumslayer » Thu Jul 16, 2009 8:21 am

A view will not be able to get access to any model if the model being accessed is not set by the controller. Thus the following will work:

Code: Select all

$this->getModel('openings'); // called from a view
only if the model was set at the controller, thus:

Code: Select all

$model = $this->getModel('openings');
$view->setModel($model, true); // by true, the model becomes default for the view

Xter_
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Jul 23, 2009 10:53 pm

Re: get Model not returning a model

Post by Xter_ » Fri Jul 24, 2009 12:58 pm

you can also do this in the view :

Code: Select all

$model =& JModel::getInstance("foo","ComponentModel");
this load a model class called 'ComponentModelFoo' located in 'models/foo.php'.
don't know if this help...

User avatar
ongray217
Joomla! Intern
Joomla! Intern
Posts: 67
Joined: Sat Jun 14, 2008 4:07 pm
Location: Kuala Lumpur, Malaysia
Contact:

Re: get Model not returning a model

Post by ongray217 » Fri Sep 11, 2009 12:36 pm

Hi ianmac,

Code: Select all

$model1 = &$this->getModel('Model1Name', 'ModelPrefix');
// will load ModelPrefixModelModel1Name from file model1name.php in models directory
can this work if i want to call Model from another component? I get a blank page when i try to do this.
Raymond Ong (ongray[at]evolucent[dot]net)
Website: http://www.evolucent.net

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: get Model not returning a model

Post by ianmac » Fri Sep 11, 2009 1:23 pm

ongray217 wrote:Hi ianmac,

Code: Select all

$model1 = &$this->getModel('Model1Name', 'ModelPrefix');
// will load ModelPrefixModelModel1Name from file model1name.php in models directory
can this work if i want to call Model from another component? I get a blank page when i try to do this.
Sure but I think JModel has an addPath or some method (you'll have to check on api.joomla.org for the exact name) that you'll have to call to add the path to your model first.

Ian

User avatar
MrS.Siam
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 158
Joined: Mon Aug 06, 2007 2:18 am
Location: Nonthaburi Thailand
Contact:

Re: get Model not returning a model

Post by MrS.Siam » Fri Sep 11, 2009 2:11 pm

Normally I use this way in my development

In controller

Code: Select all

       $model1 = & $this->getModel( 'model1', 'ModelPrefix' );
       $model1->setId(JRequest::getInt('id', 0));
       //-------- any operation on Model1
       $model2 = & $this->getModel( 'model2', 'ModelPrefix' );
       //---------any operation on Model2
       $view = & $this->getView('ViewName', 'html');

       $view->setModel( $model1, true );
       $view->setModel( $model2);

       $view->display();

In View, assume that the each model contains getData() method.

Code: Select all

        //if not specify model name, it get from default model
        $data_from_model1 = $this->get('Data', 'model1');
        $data_from_model2 = $this->get('Data', 'model2');  
        
It is just showing a relation concept between controller and view. Hope this help?
Help to build Joomla! community
http://www.joomlant.com

User avatar
mokelly
Joomla! Guru
Joomla! Guru
Posts: 617
Joined: Sun Jul 20, 2008 10:57 am
Location: Royse City, Texas USA
Contact:

Re: get Model not returning a model

Post by mokelly » Wed Oct 21, 2009 7:23 pm

Code: Select all

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.controller' );
class emergencypreparednesscontrollerinventory_detail  extends JController
{
	function __construct( $default = array())
	{		
		JRequest::setVar( 'view', 'inventory_detail' );
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar( 'hidemainmenu', 1);
		$post	= JRequest::get('post');
		If(isset($post['assetdescription']) AND strlen(trim($post['assetdescription'])) > 0 ){		
			$this->saveassettype();
		}
		If(isset($post['NewKeyword'][1]) AND strlen(trim($post['NewKeyword'][1])) > 0){	
			$this->savekeyword();
		}
		parent::__construct( $default );
		$this->registerTask( 'add'  , 	'edit' );
	}
	function save()
	{	
		$model = $this->getModel('inventory_detail');
		If($model->saveinventory()){		
			$this->setRedirect( 'index.php?option=com_emergencypreparedness&controller=inventory',$msg );
		}else{		
			$this->setRedirect( 'index.php?option=com_emergencypreparedness&controller=inventory_detail',$msg );
		}
	}
	function saveassettype()
	{	
		$model = $this->getModel('inventory_detail');
		$model->saveassettype();
	}	
	function savekeyword()
	{	
		$model = $this->getModel('inventory_detail');
		$model->savekeyword();
	}
	function cancel()
	{
		$model = $this->getModel('inventory_detail');
		$model->checkin();
		$this->setRedirect( 'index.php?option=com_emergencypreparedness&controller=inventory' );
	}	
}
$model = $this->getModel('inventory_detail'); works in function save and function cancel
Does not work in function saveassettype or function savekeyword

The only difference I can see is the controller is called with task save and task cancel where function saveassettype and savekeyword are called from inside the controller. Surely there is a good reason but I would like to know why? And how do I make it work in the other two?

The two that do not work give this error:
Fatal error: Class 'JModel' not found in /srv/www/htdocs/dutchprecision.com/libraries/joomla/application/component/controller.php on line 591
CARTwebERP Where you sell, fullfill, and account for it all!

User avatar
mokelly
Joomla! Guru
Joomla! Guru
Posts: 617
Joined: Sun Jul 20, 2008 10:57 am
Location: Royse City, Texas USA
Contact:

Re: get Model not returning a model

Post by mokelly » Wed Oct 21, 2009 7:47 pm

All of these produced the same error:
$model = & $this->getModel( 'model', 'emergencypreparedness' );

$model = & $this->getModel( 'model', 'inventory_detail' );

$model = &$this->getModel('emergencypreparedness', 'inventory_detail');

$model = &$this->getModel('inventory_detail', 'emergencypreparedness');

This one produced a different error:

$this->setModel($model, 'inventory_detail')

Fatal error: Call to undefined method emergencypreparednesscontrollerinventory_detail::setModel() in /components/com_emergencypreparedness/controllers/inventory_detail.php on line 33
CARTwebERP Where you sell, fullfill, and account for it all!

User avatar
juanparati
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 123
Joined: Thu Nov 08, 2007 6:00 pm
Location: Aarhus (Denmark)

Re: get Model not returning a model

Post by juanparati » Wed Oct 21, 2009 7:57 pm

For load a model from a direct view, I use this:

Code: Select all

$model = & $this->getModel( 'model', 'method' );
For example, model categories and view categories.

But this method do not work when you need instance a model from a indirect view or module, plugin, etc.

In this cases I prefer include the module file and call to the constructor:

Code: Select all

require_once(JPATH_COMPONENT.DS.'models'.DS.'myothermodel.php');
$model=new ComponentModelmyothermodel;
From the code to the reality!

User avatar
mokelly
Joomla! Guru
Joomla! Guru
Posts: 617
Joined: Sun Jul 20, 2008 10:57 am
Location: Royse City, Texas USA
Contact:

Re: get Model not returning a model

Post by mokelly » Wed Oct 21, 2009 8:03 pm

Code: Select all

		require_once(JPATH_COMPONENT.DS.'models'.DS.'inventory_detail.php');
		$model=new emergencypreparednessModelinventory_detail;
This worked but I had to use it in both functions. Seems like overkill having to include the 336 line model file twice, just to get two functions. I could violate the MVC standards I suppose.

I do want to follow the standards but it seems that the inconsistencies cost me almost as much time as I save using Joomla for development.

It would be wonderful if there were one way to call a method from a model from a controller, the model itself, the view script, and the form or default script. Just one way to do it everytime with consistency!
CARTwebERP Where you sell, fullfill, and account for it all!

User avatar
mokelly
Joomla! Guru
Joomla! Guru
Posts: 617
Joined: Sun Jul 20, 2008 10:57 am
Location: Royse City, Texas USA
Contact:

Re: get Model not returning a model

Post by mokelly » Wed Oct 21, 2009 8:07 pm

As long as I am wishing I wish that I could somehow find the line of code in my component that causes the core to blow up. As it is I have to put a echo "stop";exit; before every suspect line of my code until the core error message stops. Does anyone know of a quicker way?
CARTwebERP Where you sell, fullfill, and account for it all!

onickel1
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Fri Apr 17, 2009 9:41 am

Re: get Model not returning a model

Post by onickel1 » Thu Oct 22, 2009 11:56 am

mokelly wrote:As long as I am wishing I wish that I could somehow find the line of code in my component that causes the core to blow up. As it is I have to put a echo "stop";exit; before every suspect line of my code until the core error message stops. Does anyone know of a quicker way?
Forgive me, if i didn't understand you.
Do you mean debug? You can use eclipse and it shows you every on debugmode.
check out:http://docs.joomla.org/Setting_up_your_ ... evelopment

I've a question though.
I understand, the right way to use the mvc concept, is by using this->get('method') in the view, which uses the model previously defined in the controller.
But what happens, if the method requires a parameter?
E.G.
i need the $_POST, to do a search in db according to user's input.
I have a method in the model, which requires it to do the query.

Code: Select all

class BlaBlaModelBla {
    function getBlaBla($post) {
        query = SELECT * FROM #__blabla WHERE name LIKE $post[name]
                    and so on
    }
}
In the controller I get the $_POST using JRequest and pass it to the view

Code: Select all

$view=& $this-> getView('Bla');
$view->display($post);
The view passes the $post to the method in model and get the results and it displays it in the template

Code: Select all

$model =   &$this->getModel();
$row =   $model->getBlaBla($post);
		
$this->assignRef('row'   , $row); 
It works fine, but inn other computers, i get the famous "non-object method call up" error.
So, i was wondering, if i get the $_POST directly from the model. That would spare variables passing over.
But is this approach correct?

User avatar
toncmi
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Thu Feb 07, 2008 3:08 pm
Contact:

Re: get Model not returning a model

Post by toncmi » Sat Oct 24, 2009 4:42 am

mokelly wrote:

Code: Select all

		require_once(JPATH_COMPONENT.DS.'models'.DS.'inventory_detail.php');
		$model=new emergencypreparednessModelinventory_detail;
This worked but I had to use it in both functions. Seems like overkill having to include the 336 line model file twice, just to get two functions. I could violate the MVC standards I suppose.

I do want to follow the standards but it seems that the inconsistencies cost me almost as much time as I save using Joomla for development.

It would be wonderful if there were one way to call a method from a model from a controller, the model itself, the view script, and the form or default script. Just one way to do it everytime with consistency!
:D :D That right
Signature rules: Literal URLs only - http://forum.joomla.org/viewtopic.php?f=8&t=65


Locked

Return to “Joomla! 1.5 Coding”