Im very new to Joomla but hav a fairly good understanding of PHP.
Basically i need to make a component for joomla and so after reading the MVC tutorials i did this successfully :D woow!
However this is my current problem:
When i access a method in my controller i need to set some variable values and then pass these to my view so i can assign them to variables in my layout. Now in the tutorials it says that the controller is used to call methods in a model to update data then this model is passed to the view, the problem is if i access a variable from the model in the view it is like this model has been re initiated and any changes made by the controller are lost.
let me show you by code
In my controller:
Code: Select all
$model =& $this->getModel();
$model->setMyData();
parent::display();
In my model:
Code: Select all
var $test= 'default';
function __construct()
{
parent::__construct();
}
function getMyData()
{
return $this->test;
}
function setMyData()
{
$this->test = 'hello from model';
}
In my view:
Code: Select all
$word = $this->get('MyData');
$this->assignRef('greeting', $word);
note: ive tried accessing the model using the same code as the controller instead of the $this->get method
So as you can see when i call the setMyData method from the controller it sets the var 'test' to 'hello from model' however when i call get('MyData') or $model->getMyData(); from the view i get 'default' which is what i set the var to when the class is constructed.
I hope you get what im saying because iv confused myself
![Huh ???](./images/smilies/huh.gif)
Am i doing something wrong? is there another way of passing data between controller and view?
Any help will be much much apreciated as ive been stuck on this for 3 days solid
![Cry :'(](./images/smilies/cry.gif)
Many thanks
Ben