Yii Framework Forum: Passing Data Without Rendering - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Passing Data Without Rendering Rate Topic: -----

#1 User is offline   Sler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 17-July 12

Posted 30 November 2012 - 09:57 AM

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

#2 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 30 November 2012 - 10:17 AM

with gloabalState maybe ?

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


and

$app->setGlobalState('LangueUtilisateur',$LangueUtilisateur);

0

#3 User is offline   Sler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 17-July 12

Posted 30 November 2012 - 10:34 AM

View Postnath-0, on 30 November 2012 - 10:17 AM, said:

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

0

#4 User is offline   LastDay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 06-March 11
  • Location:Russia

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:


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.
0

#5 User is offline   MadAnd 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 16-June 11
  • Location:Ukraine

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:
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.
0

#6 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 30 November 2012 - 11:09 AM

soory I forgot :

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


0

#7 User is offline   LastDay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 06-March 11
  • Location:Russia

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.
0

#8 User is offline   Sler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 17-July 12

Posted 30 November 2012 - 12:00 PM

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
0

#9 User is offline   MadAnd 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 16-June 11
  • Location:Ukraine

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?
0

#10 User is offline   Sler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 17-July 12

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:
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;

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users