Page 1 of 1
Passing Data Without Rendering
#1
Posted 30 November 2012 - 09:57 AM
Is there anyway to pass data into a .php file without rendering($this->render('index', $data)
?
#2
Posted 30 November 2012 - 10:17 AM
with gloabalState maybe ?
and
$lu = $app->getGlobalState('LangueUtilisateur');
and
$app->setGlobalState('LangueUtilisateur',$LangueUtilisateur);
#3
Posted 30 November 2012 - 10:34 AM
nath-0, on 30 November 2012 - 10:17 AM, said:
with gloabalState maybe ?
and
$lu = $app->getGlobalState('LangueUtilisateur');
and
$app->setGlobalState('LangueUtilisateur',$LangueUtilisateur);
It would error on app variable undefined
It i tried this, stores a crop_id into current_crop
$app->setGlobalState('curr_crop',$crop_id);
#4
Posted 30 November 2012 - 11:01 AM
Another way could be set this variables directly as field of Controller class (this class is typically located inside protected/components/Controller.php).
For example:
Now in any view controller variables could be accessed as:
But be aware of this method - variables would be shared amongst all controller actions which controllers are derived from Controller!
If it's not that you are going for - try to find some another method.
For example:
class Contoller extends CController
{
public $variable1;
public $variable2;
....
public function init()
{
$this->variable1 = 'value1';
$this->variable2 = 'value2';
...
parent::init();
}
}
Now in any view controller variables could be accessed as:
echo $this->variable1; echo $this->variable2;
But be aware of this method - variables would be shared amongst all controller actions which controllers are derived from Controller!
If it's not that you are going for - try to find some another method.
#5
Posted 30 November 2012 - 11:08 AM
Hi guys,
the use of the GlobalState is not a very good idea, if you don't really need persistent storage between sessions/requests, and just want to supply data which is needed only in the current request.
The better approach is to declare new public property in you controller class like:
and then you will be able to reference it as $this->yourProperty in all views rendered by that controller.
the use of the GlobalState is not a very good idea, if you don't really need persistent storage between sessions/requests, and just want to supply data which is needed only in the current request.
The better approach is to declare new public property in you controller class like:
class YourController extencds CController {
public $yourProperty;
...
}
and then you will be able to reference it as $this->yourProperty in all views rendered by that controller.
#6
Posted 30 November 2012 - 11:09 AM
soory I forgot :
$app = Yii::app();
$lu = $app->getGlobalState('LangueUtilisateur');
...
#7
Posted 30 November 2012 - 11:20 AM
Yes, as MadAnd corrected above, data could be set in particular controller, not only in the parent controller.
#8
Posted 30 November 2012 - 12:00 PM
This is in my view
Where should I put this line:
I would like it to activate as I click on the link. By the way I added $curr_crop on the CController
echo "     ".CHtml::ajaxLink ("$view_crop[$i]",
array('site/crtinfo' , 'crop_id'=>$fcropid[$i], 'date_id'=> null),
array('update' => '#data'))."<br/>";
Where should I put this line:
$this->curr_crop = $fcropid[$i];
I would like it to activate as I click on the link. By the way I added $curr_crop on the CController
#9
Posted 30 November 2012 - 12:09 PM
You should put the assign statement somewhere in the controller action code, before you call render().
Do you really added that new property by editing contents of the framework/web/CController.php?
Do you really added that new property by editing contents of the framework/web/CController.php?
#10
Posted 30 November 2012 - 12:41 PM
Still not working. 
I have two options in this page, a AjaxLink, which will update the crops and a AjaxButton for the date.
If i click the link,
It will update $this->curr_crop into new crop
Set crop_id to $this->curr_crop
It will set $date_id to 0
If i click the button,
It will set crop_id to $this->curr_crop
It will set date to chosen date.
Any idea how can I do this? $this->curr_crop will always go back to my old_crop or the crop that I initialize.
My ajaxLink code:
My AjaxButton code:
I have two options in this page, a AjaxLink, which will update the crops and a AjaxButton for the date.
If i click the link,
It will update $this->curr_crop into new crop
Set crop_id to $this->curr_crop
It will set $date_id to 0
If i click the button,
It will set crop_id to $this->curr_crop
It will set date to chosen date.
Any idea how can I do this? $this->curr_crop will always go back to my old_crop or the crop that I initialize.
My ajaxLink code:
echo "     ".CHtml::ajaxLink ("$view_crop[$i]",
array('site/crtinfo' , 'crop_id'=>$fcropid[$i], 'date_id'=> null),
array('update' => '#data'))."<br/>";
My AjaxButton code:
echo " ".CHtml::ajaxButton ("$label[$at]",
array('site/crtinfo', 'crop_id'=>$this->curr_crop, 'date_id'=>$dat_mod[$at]),
array('update' => '#data'));
echo $this->curr_crop;
Share this topic:
Page 1 of 1

Help













