Reputation: 7050
I have added
app_path().'/classes',
to global.php in the ClassLoader::addDirectories array. In app/classes/helpers/Url.php I have:
<?php namespace Helpers;
class Url {
public static function prep($str)
{
if ($str == 'http://' OR $str == '')
{
return '';
}
$url = parse_url($str);
if ( ! $url OR ! isset($url['scheme']))
{
$str = 'http://'.$str;
}
return $str;
}
}
Then in a view I have:
{{HTML::link(Helpers\URL::prep($place->url), $place->url, array('target' => '_blank'))}}
This works fine locally, but on my server I'm getting an error for: Class 'Helpers\URL' not found. I tried going through these steps, but it didn't work either. Any ideas?
Upvotes: 0
Views: 8052
Reputation: 184
I was following https://stackoverflow.com/a/17091089/1454622 (his "Option 1", which I prefer).
I had this same issue where it worked on my local but not on my remote server. It was directory and file permissions issues on my app/storage. My remote needed these (thanks @elliotyap ):
1) My helper class is in app/libs
, so I added to my composer.json
file in the autoload
section: "app/libs",
2) php composer.phar dump-autoload
And it also needed some permissions changes:
3) sudo chgrp THE_SERVERS_WEB_SERVER_USER_HERE app/storage
Upvotes: 0
Reputation: 7050
Ok, I found the problem. I renamed "app/classes/helpers" to "app/helpers", then added the new app/helpers to composer.json and global.php and ran composer dump. Looking through some of the PHP documentation, it seems like PHP sometimes has issues with using "class", "classes", or other reserved type words in directories and namespaces. I'm still not sure why this was working locally, but not on the server though.
Upvotes: 0
Reputation: 161
in config/app.php in the aliases
array define your Helper facade like so
'Helper' => 'Helpers\Url'
then you can do Helper::prep()
Upvotes: 1