Migrate custom Facebook util library to Yii framework - facebook

I have a facebook app developed in plain PHP, I'm migrating the app to YII framework.
The thing is that I use a class call "utilsFacebook" where I have the object facebook(of the fb sdk) and all the methods that I need to get data from facebook, getUserId, getUserFriendList, etc.
I don't know how to handle all the operations that I do in utilsFacebook with Yii.
Create a controller with the functions of utilsFacebook is the correct think to do?
Every time that I instance the controller would create a new Facebook object, Should I store that object in a SESSION to get a better performance or is a bad idea?

Q. Create a controller with the functions of utilsFacebook is the correct think to do?
Having done a facebook app using yii as the framework, i would recommend you to make this library either a component, or an extension.
But definitely don't put these functions in the controller directly. Whenever a controller needs them call the functions using your custom facebook util class.
Components can be put in the folder: projectrootfolder/protected/components
Extensions can be put in the folder: projectrootfolder/protected/extensions
If you don't believe that either of these make semantic sense, you can always create a new folder within protected, say utils and put the class there. However i think extensions is the best way to go.
Q. Should I store that object in a SESSION to get a better performance or is a bad idea?
I don't think it's necessary to store the object in a session, because there will be no visible performance gain. Further you'll complicate your code unnecessarily.
What i had done was, created an app level component and used this component throughout the app, in any controller.
Example:
In your application's config, protected/config/main.php :
'components'=>array(
'fbHelper'=>array( // gave the component this name
'class'=>'ext.utils.FacebookHelper', // had stored the helper class in extensions/utils folder
'parameter1'='somevalue',
// more parameters
),
// standard yii app components
),
This will allow you to use the component like this: Yii::app()->fbHelper->getFriends();
Take a look at the facebook-opengraph extension, which could help you, on the way.

Related

How to access SAPUI5 component from utility functions?

I would like to access my SAPUI5 app component using this.getOwnerComponent() from a utility function, for example formatter or a class function, this works from controllers but in a utility or formatter function placed in another folder doesn't work. I do not want to use sap.ui.getCore(), is there any other way to do it?
I ended up with below two choices:
1. Create the utility functiona as a singleton class and pass the component one time with a setComponent method.
2. Use event bus to fire events and get things done by component that can be done only within the component like accessing oData resources
You could pass the controller instance to your utility class in the constructor, and then access its owner component. You could also try injecting the component directly. Unfortunately, I am not sure if any of these is the preferred way in UI5 development.
That would couple the utility function to the component logic though, which I do not think is a good idea, you probably should pass only what is required for the utility function to do its' job.

Create an App within an App

I am being presented with a very interesting project. The task that I must complete is to figure out a way to allow a partner to be involved in an app without giving up their source code. The code will be included in the main bundle of the app so it is not dynamically stored. The partner has a fully functional app that is needed to be ran in a window within the main app at the appropriate time. I know having the partners create a web app would be ideal so it is treated like a webpage but I am more concerned with codes that must be written natively in iOS.
My question is what is the best way to go about solving this? In theory it is like an App within an App. Is there a way if they gave up their .app file I can include this in the bundle and then run it when I catch a certain event? Should I have the partners create their code in a framework and then import into the shell project? What is the best way to approach this problem?
If your 2nd-party doesn't want to provide you with the source code, why doesn't he compile it to object code then let you simply link it to your app?
By the way, at least on official (non-jailbroken) iDevices, apps can't 'embed' or 'open' one another in such a way - you can open an app programmatically if 1. it's a separate app 2. it has a registered special URL associated to its bundle.
Is there a way if they gave up their .app file I can include this in
the bundle and then run it when I catch a certain event?
No, you'll want to have them create a library instead. You can then include that library in your project.
Creating a library is as simple as:
Choose File->New...->Project... in Xcode.
Select the "Cocoa Touch Static Library" project template.
Add your code.
Build.
The result is a static library that you can add to your application(s). The library will contain the compiled code that you added, but doesn't include the source code. The library developer should provide whatever header files are necessary to use the code in the library.
An App within an App is possible however it requires a common data framework that allows one app to reference the same data without confusing the the source of and destination of the data.
Such a framework allows one app to interact with another app referencing the same data.

Can I call session in template/view on Play Framework

I'm new at using Play Framework 2.0 (I am using Scala) and have a question about sessions.
I come from a Ruby on Rails background, so I tend to think of everything that I learn in Play Framework with respect to Ruby on Rails.
With that in mind, is there any way for me to call stuff stored in the Session while I am in the view?
If I have "hello" -> "world" stored in the Session, I want to be able to do something like #session.get("hello") and be able to use "world" in the view. Is this possible?
The other option I see is to store the value in a variable in the controller, and pass that along to the view by doing something like OK( var ), but that way seems kind of clunky especially if I start using more variables.
Thanks!
Sessions in Play store in cookies and are really just for cross-request data. If that is what you want then you can use #session.get("hello") but what you might actually be after is a way to pass stuff from controllers to templates without having to specify them as parameters. In that case, see the very detailed answer to that question here:
https://stackoverflow.com/a/9632085/77409
Yes you can use #session.get("hello") in template, however it looks that you need to specify at least implicit parameter named 'session' at the beginning of the template when using templates with Scala controllers:
#()(implicit session: play.api.mvc.Session)
Also there is flash scope - it differs from session that it lives only for one request and is not signed. So it is most often used just for transporting error/inf messages.
See Session and flash scopes doc
Finally as each template is just a Scala function, you can also call some action from your controller and retrieve session data
You can definetly call ur session in play templates.
Try this code - it works in views:
$session.session_variable_name;

How to get request properties in routeStartup plugin method?

I'm developing a multilanguage application, and use routes with translated segments. For multilingual support I created special Multilingual plugin.
To use translated segments I need set translator for Zend_Controller_Router_Route before routes init. So only possible place for this in my plugin is routeStartup method, but there is one problem here - for determine right locale I need to use properties of request (Zend_Controller_Request_Abstract), like module, controller and action names, but they are not defined yet here in routeStartup method. They are already defined, for example, in routeShutdown - but I can't set translator for route there, because it have to be done before routes init.
So what can I do:
can I get request properties somehow in routeStartup
or can I re-setup translator later in routeShutdown
P.S: there is a question with exactly the same problem Zend_Controller_Router_Route: Could not find a translator, but proposed answers is not the option for me, because I can't just retrieve language code from url with Regex, I have much more complicated code to define right language code.
Thanks.
What about putting your code in preDispatch? That's what I personally do when I need to check if the person is logged in. Maybe you can move your code there too?

How do I write an extension for Sinatra without packaging it as a gem?

I want to include the distance_of_time_in_words method in a sinatra app
I don't want to package and distribute a gem, which is what the Sintra docs direct you to do. I just want that method accessible in my view.
What's the easiest way to do this? Thanks.
On http://www.sinatrarb.com/intro.html look at Helpers section and define helper methods for use in route handlers and templates
Just place the file somewhere in your ruby load path ($LOAD_PATH) and require it. Or place the code directly in your app file.