Questions regarding fuel_model()

edited November 2011 in Modules
I want to create an adverts module which will render 2 advertising blocks, one for horizontal banners, the other for vertical. The selection would be random. The "quotes" module in the Widgicorp demo looks like a good example of the kind of thing I want, but I don't fully understand what "fuel_model()" does in rendering these quotes - particularly the array parameters.

Firstly, what qualifies a model to be accessible by fuel_model()? Is it simply by having an array declared in MY_fuel_models?

Secondly, what do the array argument elements mean? For example, the quotes block has:

fuel_model('quotes', array('find' => 'one', 'order' => 'RAND()'));

Obviously, this gets one random quote, but how?

The 1st argument ('quotes') refers to...? The table? The class however is 'quotes_model'. There is no $record_class defined in that model either.

The user guide suggests the (1st) argument as:

"module - specifies the module folder name to find the model"

What folder? The model is in the application/models folder, as is typical - it's not an advanced module. Further, on what function of the model is the "find" operating on - there is nothing like "function one()" in the quotes_model.php. There must be some convention I'm unaware of.

When I try to use fuel_model() on my adverts model, I get "Message: Trying to get property of non-object". It has an entry in the MY_fuel_modules.php config however. In fact I get this message on most (but not all) models, however, all the FUEL models either work or do not explicitly error? The fuel_model() function looks like one of the most useful features I've found recently, and I want to be able to use it with confidence!

Comments

  • edited November 2011
    OK, I solved my immediate problem - the "quotes" example uses
    $quote->name
    to extract its data. I couldn't get this to work (like for like) in my example, however using the index name of the returned array did eg
    $hz_ad['url']

    The earlier questions still stand though! I only reached this point by using gettype() to analyse what I was getting and guessing!
  • edited 12:39AM
    I think instead of me trying to explain the answers, take a look at the method in /modules/fuel/helpers it's quite short and easy to follow.. It'll probably be more succinct than my ramblings!
  • edited 12:39AM
    The first parameter "module" refers to the module key name in your MY_fuel_modules.php file. It uses that value to get the module information including what "model" is associated with the module using the "model_name" parameter". The other "module" parameter refers to the "Advanced" module name or folder that the model exists in (I understand the confusion).
Sign In or Register to comment.