MVC - Passing data between Controller and View via Model - Joomla! Forum - community, help and support
hi there,
im new joomla hav understanding of php.
basically need make component joomla , after reading mvc tutorials did successfully :d woow!
however current problem:
when access method in controller need set variable values , pass these view can assign them variables in layout. in tutorials says controller used call methods in model update data model is passed view, problem if access variable model in view model has been re initiated , changes made controller lost.
let me show code
in controller:
in model:
in view:
note: ive tried accessing model using same code controller instead of $this->get method
so can see when call setmydata method controller sets var 'test' 'hello model' when call get('mydata') or $model->getmydata(); view 'default' set var when class constructed.
i hope im saying because iv confused myself lol
am doing wrong? there way of passing data between controller , view?
any much apreciated ive been stuck on 3 days solid
many thanks
ben
im new joomla hav understanding of php.
basically need make component joomla , after reading mvc tutorials did successfully :d woow!
however current problem:
when access method in controller need set variable values , pass these view can assign them variables in layout. in tutorials says controller used call methods in model update data model is passed view, problem if access variable model in view model has been re initiated , changes made controller lost.
let me show code
in controller:
code: select all
$model =& $this->getmodel();
$model->setmydata();
parent::display();
in model:
code: select all
var $test= 'default';
function __construct()
{
parent::__construct();
}
function getmydata()
{
return $this->test;
}
function setmydata()
{
$this->test = 'hello model';
}
in view:
code: select all
$word = $this->get('mydata');
$this->assignref('greeting', $word);
note: ive tried accessing model using same code controller instead of $this->get method
so can see when call setmydata method controller sets var 'test' 'hello model' when call get('mydata') or $model->getmydata(); view 'default' set var when class constructed.
i hope im saying because iv confused myself lol
am doing wrong? there way of passing data between controller , view?
any much apreciated ive been stuck on 3 days solid
many thanks
ben
i believe part of mistake creating instance of model through controller. step unnecessary (and perhaps real source of error).
the component know model use based on view using -- , automatically.
if have 1 controller, 1 model , 1 view, make sure use appropriate naming conventions indicated in mvc tutorial.
the component know model use based on view using -- , automatically.
if have 1 controller, 1 model , 1 view, make sure use appropriate naming conventions indicated in mvc tutorial.
Comments
Post a Comment