|
You are here: Home / Boxes in Sitellite: Basic Building Blocks |
Boxes in Sitellite: Basic Building BlocksThe access.php FileAccess settings for both boxes and forms are contained in access.php files, which act a lot like Apache's .htaccess files do. They even inherit from parent folders, so you can define a single access.php file for a whole bunch of boxes. In this case, let's create an access.php file and put it in the same folder as our index.php file. In it, we'll put:; <?php /* sitellite_access = public sitellite_status = approved sitellite_action = on ; */ ?> This tells Sitellite that the box is public, approved, and that it can be called as an action. Now try loading the aforementioned URL and see what happens. Not bad, eh? And of course, passing parameters to a box from the URL is the same as passing parameters to any ordinary web page request. Here are some additional values that may be present in an access.php file:
The $box arraySince boxes are loaded within a separate namespace than the global one, global variables and objects aren't accessible directly, but instead must be explicitly imported into the current namespace. However, Sitellite does provide several variables defined specifically for the use of your box. The first of these is the $box array. Typing the following into our test box will display for you the contents of the $box array:<?php info ($box); ?> As you will see, this array has two elements in it: context and parameters. First I'll describe what the context is/does, and then I'll discuss the parameters. Switching contextsSince boxes can be called in so many different ways (the 5 we saw above), it can be useful for a box to react differently depending on the way in which it is called. For example, if a box is called in a sidebar, it may be innappropriate to call page_title(), which would override the title already set for the current page. For this, we have the concept of contexts.By default, there are 4 types of contexts, but you can also specify custom ones manually, if you should so desire, via the loader_box() function. The 4 core contexts are:
To do different things depending on the context, you might structure your PHP code as follows: <?php
switch ($context) {
case 'action':
page_title (intl_get ('My Very Own Box'));
break;
case 'inline':
printf ('<h2>%s</h2>', intl_get ('My Very Own Box'));
break;
case 'normal':
default:
// leave it to the caller to set the title
}
// output the rest as usual
?>
You probably noticed here that I used $context instead of $box['context']. A hint to save you some typing, both $box['context'] and $box['parameters'] are accessible as just $context and $parameters. Next: The $parameters array Page 1: As I mentioned in my previous ar... |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |