PHPackages                             oxboot/controller - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. oxboot/controller

ActivePackage[Framework](/categories/framework)

oxboot/controller
=================

WordPress package to enable a basic controller when using Blade with Sage 9

v1.0.0-alpha4(7y ago)07251MITPHPPHP &gt;=5.6.0

Since Jan 20Pushed 7y agoCompare

[ Source](https://github.com/oxboot/controller)[ Packagist](https://packagist.org/packages/oxboot/controller)[ Docs](https://github.com/oxboot/controller/)[ RSS](/packages/oxboot-controller/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (5)Used By (1)

Controller
==========

[](#controller)

WordPress package to enable a controller when using Blade with [Sage](https://roots.io/sage/)

- [Installation](#installation)
- [Setup](#setup)
- [Usage](#usage)
    - [Overview](#overview)
    - [Basic Controller](#basic-controller)
    - [Using functions](#using-static-methods)
    - [Using components](#creating-components)
    - [Inheriting the tree/hierarchy](#inheriting-the-treehierarchy)
    - [Creating global properties](#creating-global-properties)
    - [Advanced Custom Fields module](#advanced-custom-fields-module)
    - [Template override option](#template-override-option)
    - [Lifecycles](#lifecycles)
    - [Disable option](#disable-option)
- [Blade Debugger](#blade-debugger)
- [Blade Coder](#blade-coder)

Installation
------------

[](#installation)

### Composer:

[](#composer)

[Sage](https://roots.io/sage/) ships with Controller. However, should you need to install, browse into the Sage theme directory and run;

```
$ composer require soberwp/controller:2.1.1
```

### Upgrading to 2.x.x:

[](#upgrading-to-2xx)

Please note that versions 2.x.x are newer releases than 9.x.x-beta. The 9 was used to match Sage 9 versioning at the time.

Controller 2.x.x uses [PSR4 autoloading](https://www.php-fig.org/psr/psr-4/) to load Controller classes. This is considered best practice. You will need to [update the following files](https://github.com/roots/sage/pull/2025/files) from 9.0.0-beta versions.

Folder `controllers/` changes to `Controllers/`, class file names changes to camelcase `App.php` and `FrontPage.php`. Controller namespaces changes to `namespace App\Controllers;`

### Requirements:

[](#requirements)

- [PHP](http://php.net/manual/en/install.php) &gt;= 7.0

Setup
-----

[](#setup)

By default Controller uses namespace `Controllers`.

Controller takes advantage of [PSR-4 autoloading](https://www.php-fig.org/psr/psr-4/). To change the namespace, use the filter below within `functions.php`

```
add_filter('sober/controller/namespace', function () {
    return 'Data';
});
```

Usage
-----

[](#usage)

### Overview:

[](#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 as `class App extends Controller`
- 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` in `App.php` can be run in Blade using `App::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`

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;

[](#basic-controller)

The following example will expose `$images` to `resources/views/single.blade.php`

**app/Controllers/Single.php**

```
