Created
January 23, 2015 07:29
-
-
Save setkyar/7d14b3d8e963d8d146d4 to your computer and use it in GitHub Desktop.
Laravel 4 Helper Class Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create New Folder Call MyClass on `app/` directory | |
Add new line on `/app/start/global.php` | |
ClassLoader::addDirectories(array( | |
app_path().'/commands', | |
app_path().'/controllers', | |
app_path().'/models', | |
app_path().'/database/seeds', | |
app_path().'/MyClass', // This line is the one we need to add | |
)); | |
Create a file in `app/MyClass/Helper.php` and add such as like | |
<?php namespace Helpers; | |
class Helper { | |
public static function helloWorld() | |
{ | |
return 'Hello World'; | |
} | |
} | |
All you would need to do is call `Helpers\Helper::helloWorld();` | |
You could also **alias** this helper class in your `/app/config/app.php` file. Just add something like this to the end of the aliases array: | |
'Helper' => 'Helpers\Helper' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See more on SO