Skip to content

5.1 Build your own outlet

Lucas F. Lu edited this page Jan 30, 2020 · 5 revisions

Build an outlet instance

Building an outlet and attach it to the framework is simple. All we need is just an outlet instance that defines the nature of the outlet.

We can use the outlet class to instantiate a variable and attach it to the framework within a service provider's boot method.

An outlet consist of a "view", a callback and a list of all resources needed at the front end. How outlet behaves once loaded into the placeholder is solely up to the developer. You may create additional routes to capture function request or simply display a message when outlet is rendered.

use \feiron\felaraframe\lib\outlet\feOutlet class to create an outlet instance.

app()->frameOutlet->bindOutlet('Fe_FrameOutlet', new \feiron\felaraframe\lib\outlet\feOutlet([
            'view' => 'View file',
            'myName' => 'My new outlet',
            'reousrce' => [
                //absolute path to the front-end libraries if needed.
            ]
        ]));

An outlet is created like this, and the next time "Fe_FrameOutlet" placeholder is rendered, this newly created outlet will be rendered with a tab on the top named "My new outlet"

  • we use service container's instance "frameOutlet" to add an outlet, and pass in an outlet instance.
  • feOutlet constructor takes one parameter that defines some default configurations of the outlet.
  • "view" parameter defines the view to be used.
  • "myName" is the unique name stores in the list of outlet bank.
  • "resources" is a list of third party front-end libraries needed when rendering the outlet view.

Of course, you may create an instance first, make some changes then attach it to the outlet register.

$myOutlet = new \feiron\felaraframe\lib\outlet\feOutlet([ 'myName' => 'My new outlet']);
$myOutlet->setView('felaraframe:viewfile');
$myOutlet->pushResource(asset('path/to/asset/files'));
app()->frameOutlet->bindOutlet('Fe_FrameOutlet', $myOutlet);

Note: This outlet is registered to "Fe_FrameOutlet" place holder. It will be rendered at the control panel page. You can head over to that URL to see the changes.


List of available functions from outlet class

  1. setName($outletname):

    Sets the name of the outlet.

  2. MyName():

    Gets the name of the outlet.

  3. setCallback(callable $callback):

    Sets a callback for the outlet.

  4. CallOutlet():

    Performs the callback registered with the outlet.

  5. setResource($reousrce):

    Replace the resource list with the value of the input.

  6. pushResource($reousrce):

    Append the resource to the list.

  7. getResource($reousrce):

    Get the resource list of the outlet.

  8. setView( $view):

    Sets the view file of the outlet. $view is of type "\Illuminate\View\View".

  9. getView($flush = false):

    Returns the view. Render the view if $flush is set to True.