layout | class | title | description | menu_title | menu | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
documentation |
page-docs |
Global Package Methods - Developing - Cradle |
Global Package Methods are virtual methods defined in the bootstrap folder to allow you to manipulate it on your custom projects. |
Global Package Methods |
|
Global Package Methods are virtual methods accessible using cradle('global')
,
cradle()->package('global')
or $this->package('global')
depending on which
scope you are in. The majority of the Global Package Methods are defined in
the /bootstrap
folder to allow you to manipulate it on your custom projects.
Given a key, returns the absolute path relative to your project. The possible keys are as follows.
root
-[root path]
app
-[root path]/app
bootstrap
-[root path]/bootstrap
config
-[root path]/config
module
-[root path]/module
compiled
-[root path]/compiled
public
-[root path]/public
upload
-[root path]/upload
template
-[root path]/template
vendor
-[root path]/vendor
cradle('global')->path('config');
You can also set more paths like the following example.
cradle('global')->path('foo', __DIR__ . '/bar');
Retrieves a configuration from your /config/
folder.
//returns the array found in config/settings.php
cradle('global')->config('settings');
//returns the value of environment found in config/settings.php which is 'dev'
cradle('global')->config('settings', 'environment');
You can also write to a configuration file like the following example.
//sets foo to bar in config/settings.php
cradle('global')->config('settings', 'foo', 'bar');
//creates a file config/foobar.php and sets foo to bar
cradle('global')->config('settings', 'foobar', [
'foo' => 'bar'
]);
Make sure you chmod 777 your config folder
Returns a service object.
cradle('global')->service('sql-main'); //--> PDO
cradle('global')->service('elastic-main'); //--> Elasticsearch\ClientBuilder
cradle('global')->service('redis-main'); //--> Predis\Client
cradle('global')->service('rabbitmq-main'); //--> PhpAmqpLib\Connection\AMQPLazyConnection
If the key you provide is not a supported service, the array configuration will
return.
A wrapper to redirect to another URL
cradle('global')->redirect('/some/path');
Checks to see if the user is logged in and redirects to the login page if not.
cradle('global')->requireLogin();
Sets a flash message that will be consumed on the next URL request.
cradle('global')->flash('Something good happened', 'success');
cradle('global')->flash('Something happened', 'warning');
cradle('global')->flash('Something bad happened', 'error');
cradle('global')->flash('Something', 'info');
Translate the given string based on the current language
$name = cradle('global')->translate('Name'); //--> nom
Renders a template using Handlebars.
$handlebars = cradle('global')->template('/path/to/template', [
'foo' => 'bar',
'zoo' => 'Went to the zoo.'
]);
Returns the global Handlebars instance
$handlebars = cradle('global')->handlebars();