FAQ’s

Custom actions FAQ


Deprecated: Function create_function() is deprecated in /var/www/docs.appzio.com/public/wp-content/plugins/wp-gfm/markdown.php on line 301

Deprecated: Function create_function() is deprecated in /var/www/docs.appzio.com/public/wp-content/plugins/wp-gfm/markdown.php on line 302

Q: Public function tab1() inside the action’s controller. So this is default tab content as I understand? What else about the tabs?

A: We can have tabs in actions, but they are not a must. If there is only tab1 defined in the controller, this is used to return the view. Advantage on using tabs is that all tab content is preloaded, so responsiveness is very good when you switch between the views of a single action.

Q: How do I control what happens inside the action?

A: You can put the main controller code on the tab1() and control what the action is doing using menuid’s. Ie. you define a menuid to any element and then within the main controller code (tab1()) you can choose what happens when a certain menu id is clicked.

Q: I see scroll and header on the example code. What are the parts of the view.

A: To create the view, we have the following arrays:

$this->data->header
$this->data->scroll
$this->data->footer
$this->data->onload

You don’t need to define all of them, but if you do, they need to be arrays and each array item must contain an object. If you need to do nested structures, you do that with getRow and getColumn. The objects that go inside the view arrays could be written directly as json, but we have component functions to make this easier. So instead of writing the entire object for getting a text (and creating a huge controller), you simply write $this->getText(‘My text’). So adding a text becomes $this->data->scroll[] = $this->getText(‘My text’).

Onload is little different, as it behaves like a menu. You can add any menu command into the onload block, so it can do things like refreshing view, completing action, connecting with facebook, getting location and many other things.

Q: How to we handle images? What are the paths?

To add an image to your action, you would write:

$this->data->scroll[] = $this->getImage('myimage.png');

myimage.png would need to be inside the theme/images directory or if action doesn’t use themes, inside the main images directory. If you need to add images and then access them, you could do like this:

$path = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/documents/games/' . $this->gid . '/instagram/';
mkdir(0777,true);
copy($myimage,$path.$myimage);

When calling for the image, you don’t need to specify the path, but you will need to have the original file name that you use for calling.

Q: How can add some configuration options that the admin can set from the web interface?

If you want to make some option configurable, you can add the configuration option inside the file in forms directory. So for example this inside the configuration array:

'config[source_url]' => array('type'=>'text', 'title'=>'{%source_url%}'),

Can be referred to inside the code like this:

$sourceurl = $this->getConfigParam('source_url');

Q: Data from third parties, should client access it directly?

As a general design principle client will get data only from Appzio backend. And any third party data should be cached wherever possible to create the best possible user experience. So you can do it like this for example:

$cache = Appcaching::getGlobalCache($this->gid.'newsdata');

if(!$cache){
 $this->loadNews();
}

and in loadnews you would have this bit to save the data:

Appcaching::setGlobalCache($cachename,$data,7200);

We are piping all cache requests through Appcaching class (ie. please don’t use Yii’s caching functions directly). And note about the scope of the data that if you want it to be user specific, you should use $this->playid as an identifier, if its app specific, $this->gid would work ok.

Q: What are all the different id’s I see around?

Since all Appzio apps have a state which is connected to user, there are few id’s that you see flying around. Here is a short summary of the most important one:
$this->gid = id for the app
$this->userid = tied to user’s certain app installation, use only if you know what you are doing
$this->playid = we using this to refer to a unique user
$this->action_id = id for the action object, ie. actions master configuration as defined in the web admin
$this->actionid = representation of the action as seen by the user. Ie. each action_id’s will have an object for each play_id

Q: Where should I save all the data?

Each app has variables, that can be set by user’s activity or they can be set from the serverside. These are not meant