BaseBlock
The BaseBlock.php file in the Core directory of the PHPFast framework defines an abstract class BaseBlock to manage blocks in the application. Below is a detailed explanation of the methods in this file.
getName() and setName()
getName() and setName()<?php
// Returns the block name, e.g., "HeaderBlock"
protected function getName(){
return ucfirst($this->name);
}
protected function setName($value){
$this->name = $value;
}The
getNamemethod returns the block name with the first letter capitalized.The
setNamemethod sets the value of the$nameproperty.
getLabel() and setLabel()
getLabel() and setLabel()<?php
protected function getLabel(){
return $this->label;
}
protected function setLabel($value){
$this->label = $value;
}The
getLabelmethod returns the value of the$labelproperty.The
setLabelmethod sets the value of the$labelproperty.
setProps() and getProps()
setProps() and getProps()<?php
public function setProps(array $props) {
$this->props = array_merge($this->props, $props);
return $this;
}
protected function getProps() {
return $this->props;
}The
setPropsmethod sets the properties for the block by merging the provided$propsarray with the current$propsarray.The
getPropsmethod returns the properties of the block.
handleData()
handleData()<?php
// Handle data and return it in the format required by the layout file
abstract public function handleData();The abstract method handleData is responsible for processing data and returning it in the format required by the layout file. This method will be implemented in the subclasses that extend BaseBlock.
Example
<?php
namespace App\Blocks\Content;
use System\Core\BaseBlock;
use App\Models\UsersModel;
class ContentBlock extends BaseBlock {
public function __construct() {
$this->setLabel('Content Block');
$this->setName('Content');
$this->setProps([
// layout name: layout_1.php
'layout' => 'layout_1', // Required
'other_properties' => 'Other properties', // Other Properties
]);
$this->usersModel = new UsersModel();
}
public function handleData() {
$props = $this->getProps();
$users = $this->usersModel->getUsers();
return [
'props' => $props,
'users' => $users,
];
}
}Find out how to use Block
Summary
The BaseBlock class in the BaseBlock.php file defines the basic properties and methods to manage blocks in the application. The main methods include:
getNameandsetName: Get and set the block's name.getLabelandsetLabel: Get and set the block's label.setPropsandgetProps: Set and get the block's properties.handleData: An abstract method to process the block's data.
Last updated
Was this helpful?