Blog

Developers Tip: Working with blocks in phpFox 4.3

Creating blocks in v4 has changed a rather lot with how we create blocks in phpFox in comparison to v3. Creating blocks are done on the fly in an apps start.php file and can be placed on any controller. The current issue we faced is allowing Admins to change the location of a block and allow them to order blocks.

In our upcoming release, 4.3 we have included a new method for developers to work with blocks that will also give Admins the power to manage them.

With our current version you can create a block in your start.php using the following method.

[code]

block(1, ‘core.index-member’, function() {

echo "Hello World!";

});

[/code]

In 4.3+ you can use the current method or open up your app.json and assign blocks with unique identifiers. Here is an example

[code]
{
"id": "App_ID",
"name": "App Name",
"blocks": [
{
"callback": "unique_name",
"route": "core.index-member",
"location": 1
}
]
}
[/code]

Now that you have assigned a block you can create the callback connection in your start.php.

[code]
block(‘unique_name’, function() {
echo "Hello World!";
});
[/code]
By using this new method, it registers your block automatically to the block database, which then allows Admins to assign your block to specific routes and/or locations.

Fox