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 thisassets() โ
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.cssYou 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.phpCommandsPath() โ
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.phpControllersPath() โ
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.phpDatabasePath() โ
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/migrationsFactoriesPath() โ
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.phpHelpersPath() โ
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.phpLibPath() โ
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.phpMigrationsPath() โ
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.phpModelsPath() โ
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.phpPublicPath() โ
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.phpRoutesPath() โ
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.phpSeedsPath() โ
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.phpStoragePath() โ
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.phpViewsPath() โ
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.phpLoading 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 thisIt 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 thisAppConfig() โ
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 thisAuthConfig() โ
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 thisCorsConfig() โ
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 thisDatabaseConfig() โ
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 thisMailConfig() โ
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 thisViewConfig() โ
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