Download the PHP package chameleon2die4/sage9-components without Composer
On this page you can find all versions of the php package chameleon2die4/sage9-components. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sage9-components
Sage9 Components
Add Components controllers support to Sage 9.x.
Installation
Composer:
Install with Composer. Run in shell:
Requirements:
Setup
By default Controllers uses namespace Controllers\Components
.
Controller takes advantage of PSR-4 autoloading. To change the namespace, use the filter below within functions.php
Usage
Overview:
- Controller class names follow the same hierarchy as WordPress.
- The Controller class name should match the filename
- For example
App.php
should define class asclass App extends Controller
- For example
- Create methods within the Controller Class;
- Use
public function
to return data to the Blade views/s- The method name becomes the variable name in Blade
- Camel case is converted to snake case.
public function ExampleForUser
in the Controller becomes$example_for_user
in the Blade template - If the same method name is declared twice, the latest instance will override the previous
- Use
public static function
to use run the method from your Blade template which returns data. This is useful for loops- The method name is not converted to snake case
- You access the method using the class name, followed by the method.
public static function Example
inApp.php
can be run in Blade usingApp::Example()
- If the same method name is declared twice, the latest instance will override the previous
- Use
protected function
for internal methods. These will not be exposed to Blade. You can run them within__construct
- Dependency injection with type hinting is available through
__construct
- Dependency injection with type hinting is available through
- Use
The above may sound complicated on first read, so let's take a look at some examples to see how simple Controller is to use.
Basic Controller;
The following example will expose $images
to resources/views/partials/slider.blade.php
app/Controllers/Components/Slider.php
resources/views/partials/slider.blade.php
Parent:
In parent template use directive
resources/views/single.blade.php
Lifecycles;
Controller Classes come with two lifecycle hooks for greater control.