Passing Data Without Rendering

Is there anyway to pass data into a .php file without rendering($this->render(‘index’, $data);)?

with gloabalState maybe ?




 $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);



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:





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.

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:




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.

soory I forgot :




 $app = Yii::app();

$lu = $app->getGlobalState('LangueUtilisateur');

...




Yes, as MadAnd corrected above, data could be set in particular controller, not only in the parent controller.

This is in my view




echo "&nbsp &nbsp &nbsp".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

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?

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 &#036;this-&gt;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 "&nbsp &nbsp &nbsp".CHtml::ajaxLink ("$view_crop[$i]",

                              array('site/crtinfo' , 'crop_id'=>$fcropid[$i], 'date_id'=> null), 

                              array('update' => '#data'))."<br/>";




My AjaxButton code:




echo "&nbsp".CHtml::ajaxButton ("$label[$at]",

                              array('site/crtinfo', 'crop_id'=>$this->curr_crop, 'date_id'=>$dat_mod[$at]), 

                              array('update' => '#data'));

							  echo $this->curr_crop;