Within the Joomla VMC model it is not possible to pass any variables to the functions that are called, special with the get functions from the views object you cannot pass any variables. This is of course sometimes necessary to pass parameters to the model function that is being called.
For example a view class currently within joomla:
Code: Select all
class persons_Viewpersons extends JView {
/*
* Edit the person object
*/
function edit_person () {
// get the person object;
$person = $this->get ('person');
// now I want to fetch the person reservations from the reservations model, but I cannot pass the
// parameter for the person which would be nice
$reservations = $this-get('person_reservations' ,' reservations');
}
}
Code: Select all
class persons_Viewpersons extends JView {
/*
* Edit the person object
*/
function edit_person () {
// get the person object;
$person = $this->get ('person');
// now I want to fetch the person reservations from the reservations model
// but I cannot pass the parameter for the person which would be nice
$start_date = '2008-01-01';
$start_date = '2009-01-01';
$reservations = $this->get('person_reservations' ,' reservations',$person->id, $start_date, $end_date );
}
}
Code: Select all
function &get( $property, $default = null )
{
// If $model is null we use the default model
if (is_null($default)) {
$model = $this->_defaultModel;
} else {
$model = strtolower( $default );
}
// First check to make sure the model requested exists
if (isset( $this->_models[$model] ))
{
// Model exists, lets build the method name
$method = 'get'.ucfirst($property);
// Does the method exist?
if (method_exists($this->_models[$model], $method))
{
// The method exists, lets call it and return what we get
$result = $this->_models[$model]->$method();
return $result;
}
}
// degrade to JObject::get
$result = parent::get( $property, $default );
return $result;
}
Code: Select all
function &get( $property, $default = null )
{
// If $model is null we use the default model
if (is_null($default)) {
$model = $this->_defaultModel;
} else {
$model = strtolower( $default );
}
// First check to make sure the model requested exists
if (isset( $this->_models[$model] ))
{
// Model exists, lets build the method name
$method = 'get'.ucfirst($property);
// Does the method exist?
if (method_exists($this->_models[$model], $method))
{
$numargs = func_num_args();
if ($numargs > 2 ) {
$arg_list = func_get_args();
$args = array();
for ($i = 2; $i < $numargs; $i++) {
$args[] = $arg_list[$i];
}
return ( call_user_func_array(array( $this->_models[$model], $method),$args));
} else {
return ( $this->_models[$model]->$method() );
}
}
}
// degrade to JObject::get
$result = parent::get( $property, $default );
return $result;
}
Code: Select all
<?php
class model_reservations extends JModel{
function person_reservations( $person_id = null, $periode_start = null, $periode_end = null ) {
// here is the logic of the function
}
}
Regards,
Richard