Hi,
I'm still creating a component. In the goal to populate an edit form, I'm adding informations in my item list in the view. Exemple to populate in a form a field named testField wich is not present in the foo table:
(I detail here beacause it's quiet hard to find those informations, and this group have a good visibility in google)
my_component/views/foo/view.html
...
function display($tpl = null)
{
// get the Data
$form = $this->get('Form');
$item = $this->get('Item');
...
// Assign the Data
$this->form = $form;
$this->item = $item;
$this->item->testField = $this->get('valueForTestField');
}
The default Joomla behaviour is that $this->get('valueForTestField') call a method in the foo Model named 'getValueForTestField'.
my_component/models/foo.php
...
function getValueForTestField(&$pk="")
{
// Return the desired value
}
First Question : Is it possible to parse an argument ($pk) to this model's methods from the view ? Something like $this->get('valueForTestField', array_of_arguments) ?
Because I didn't known how to parse an argument to this function from the model, I've included a process to find the needed informations from the foo datas :
my_component/models/foo.php
...
function getValueForTestField(&$pk="")
{
if($pk="")
{
$data = $this->getItem(); // Get the infos from the 'foo table' (Joomla Core)
$pk = $data->id;
}
...
}
The goal of if($pk) is to check if the method have been called without arguments, so if it have been called from the view.
Second Question : Is there a more correct way to check in a model's method if it has been called from a view ?
Thanks a lot.