MVC Globals
Leaf MVC comes with a couple of global functions that you can use to access your app's configuration, paths and more. These functions are available globally and can be used anywhere in your app.
Loading app paths
Since Leaf MVC comes with a robust structure out of the box, it also comes with quick ways to reference files in these structures. For example, if you want to reference a file in your public
folder, you can use the PublicPath()
helper.
AppPaths()
This returns an array of all the paths in your application.
$paths = AppPaths();
$controllersPath = AppPaths('controllers'); // you can do this
$controllersPath = $paths['controllers']; // or this
assets()
This returns the path to your assets folder. You can pass in a file name to get the path to that file.
$asset = assets('css/main.css');
// -> public/assets/css/main.css
You can configure the path to your assets folder in your config/paths.php
file.
'assets' => 'public/assets'
ConfigPath()
This returns the path to your config folder. You can pass in a file name to get the path to that file.
$dbConfigFile = ConfigPath('db.php');
// -> config/db.php
CommandsPath()
This returns the path to your commands folder. You can pass in a file name to get the path to that file.
$command = CommandsPath('MainCommand.php');
// -> app/console/MainCommand.php
ControllersPath()
This returns the path to your controllers folder. You can pass in a file name to get the path to that file.
$controller = ControllersPath('MainController.php');
// -> app/controllers/MainController.php
DatabasePath()
This returns the path to your database folder. You can pass in a file name to get the path to that file.
$database = DatabasePath('migrations');
// -> app/database/migrations
FactoriesPath()
This returns the path to your factories folder. You can pass in a file name to get the path to that file.
$factory = FactoriesPath('UserFactory.php');
// -> app/database/factories/UserFactory.php
HelpersPath()
This returns the path to your helpers folder. You can pass in a file name to get the path to that file.
$helper = HelpersPath('MainHelper.php');
// -> app/helpers/MainHelper.php
LibPath()
This returns the path to your lib folder. You can pass in a file name to get the path to that file.
$lib = LibPath('MainLib.php');
// -> lib/MainLib.php
MigrationsPath()
This returns the path to your migrations folder. You can pass in a file name to get the path to that file.
$migration = MigrationsPath('MainMigration.php');
// -> app/database/migrations/MainMigration.php
ModelsPath()
This returns the path to your models folder. You can pass in a file name to get the path to that file.
$model = ModelsPath('User.php');
// -> app/models/User.php
PublicPath()
This returns the path to your public folder. You can pass in a file name to get the path to that file.
$public = PublicPath('index.php');
// -> public/index.php
RoutesPath()
This returns the path to your routes folder. You can pass in a file name to get the path to that file.
$routes = RoutesPath('_auth.php');
// -> app/routes/_auth.php
SeedsPath()
This returns the path to your seeds folder. You can pass in a file name to get the path to that file.
$seed = SeedsPath('MainSeed.php');
// -> app/database/seeds/MainSeed.php
StoragePath()
This returns the path to your storage folder. You can pass in a file name to get the path to that file.
$storage = StoragePath('MainStorage.php');
// -> storage/MainStorage.php
ViewsPath()
This returns the path to your views folder. You can pass in a file name to get the path to that file.
$view = ViewsPath('index.leaf.php');
// -> app/views/index.leaf.php
Loading app config
There are some situations that may require you to load up your config files. For such situations, we've prepared a couple of helpers to help you load up your config files.
MvcConfig()
This returns an array of all the config files in your application.
$configs = MvcConfig();
$dbConfig = MvcConfig('db'); // you can do this
$dbConfig = $configs['db']; // or this
It also allows you to load up a specific config from the config file you pass in.
$config = MvcConfig('db', 'host'); // you can do this
$config = $configs['db']['host']; // or this
AppConfig()
This returns an array of all the config in your config/app.php
file.
$configs = AppConfig();
$debug = AppConfig('debug'); // you can do this
$debug = $configs['debug']; // or this
AuthConfig()
This returns an array of all the config in your config/auth.php
file.
$configs = AuthConfig();
$auth = AuthConfig('auth'); // you can do this
$auth = $configs['auth']; // or this
CorsConfig()
This returns an array of all the config in your config/cors.php
file.
$configs = CorsConfig();
$origin = CorsConfig('origin'); // you can do this
$origin = $configs['origin']; // or this
DatabaseConfig()
This returns an array of all the config in your config/db.php
file.
$configs = DatabaseConfig();
$host = DatabaseConfig('host'); // you can do this
$host = $configs['host']; // or this
MailConfig()
This returns an array of all the config in your config/mail.php
file.
$configs = MailConfig();
$host = MailConfig('host'); // you can do this
$host = $configs['host']; // or this
ViewConfig()
This returns an array of all the config in your config/view.php
file.
$configs = ViewConfig();
$host = ViewConfig('viewEngine'); // you can do this
$host = $configs['viewEngine']; // or this