Yii Framework Forum: Storing Data To Access In All Controllers - Yii Framework Forum

Jump to content

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

Storing Data To Access In All Controllers Rate Topic: -----

#1 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 31 January 2013 - 01:43 AM

Hi ,
I have need to implement few facebook features in my application.
The problem is I need to do some server side processing of data received from Facebook. Example the friendList.

I will be doing this processing in almost all conroller.
I dont think its feasible to make a call in each controller to get facebook friends list.

Is there any way I can store the data temporary and access it in all controllers.

I dont want to save it to session. I guess it will make data slow.
and i cannot permanently save the friend list in my database I guess Issue with facebook policy.

Any directions? suggestion? please...
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 779
  • Joined: 02-July 10
  • Location:Central Poland

Posted 31 January 2013 - 04:32 AM

if you do not want to use session (but it still be much faster than fetching data in every controller) you can use cache...
red
0

#3 User is offline   developer! 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 28-November 12

Posted 31 January 2013 - 05:25 AM

you can implement it in your Controller.php component with which you can access in every controller. I have this in protected/components/ folder. you can write in before action controller. hope this following little code snippet can help you
its like this. you can write in before action so that you can access anywhere in site.
<?php

/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	public $bodyId;
	public $user;

public function beforeAction($action)
	{
		if(isset($_GET['r']))
			Yii::app()->clientScript->registerCoreScript('jquery');
		else
			Yii::app()->theme='xyz';

		// Get Facebook sessions to work in IE
		header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
....
....

//you can  write something here i'm accessing through out the site.
// get the terms
		$this->terms = Model::model()->findByAttributes(array('name'=>'terms'))->value;



 }
}


Thanks,
0

#4 User is offline   rigel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-October 12

Posted 01 February 2013 - 12:34 AM

@redguy
Hi redguy... I am new to Yii. Is it ok to save save big arrays in cache
for so many users?

@developer!
I guess you are access the data from a model to make it available every where
but facebook policy says you cannot save data like freinds list in your
own database. :(
0

#5 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 779
  • Joined: 02-July 10
  • Location:Central Poland

Posted 01 February 2013 - 04:21 AM

View Postrigel, on 01 February 2013 - 12:34 AM, said:

@redguy
Hi redguy... I am new to Yii. Is it ok to save save big arrays in cache
for so many users?

@developer!
I guess you are access the data from a model to make it available every where
but facebook policy says you cannot save data like freinds list in your
own database. :(

well... it depends. If you want to reduce number of calls to remote service to MUST store the data somehow... I mean it is rather only way to achieve what you want, but you should use cache mechanizm with some garbage collector or LRU (least recently used) removing policy to keep the cache from growing infinitely. You could try memcached (it has LRU removing policy) or some cache in database table, where you could periodically remove old records. Avoid file cache as it does not delete unused cache entries.

Session would also work well and there is garbage collector for sessions, but session is loaded every time it is needed not matter if you use all stored data or not, so it is some overhead for request that do not need this data. So if you need that data in EVERY controller and EVERY request (or almost every) - use session.
red
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