0

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?

Community
  • 1
  • 1
Chris G
  • 6,700
  • 2
  • 18
  • 20

3 Answers3

1

in config/app.php in the aliases array define your Helper facade like so

'Helper' => 'Helpers\Url'

then you can do Helper::prep()

Pushpak
  • 161
  • 2
  • 8
  • I just tried this and I'm still getting the same error, just more code from the framework was loaded first. – Chris G Aug 29 '13 at 17:41
0

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.

Chris G
  • 6,700
  • 2
  • 18
  • 20
  • you have case sensitivity issue perhaps. – itachi Aug 30 '13 at 04:13
  • Sorry, no. As stated in an above comment. I tried both ways and still was getting the same error, just in different cases. – Chris G Aug 30 '13 at 10:58
  • my helpers not loading no one server but loading on another server while i add the path into global.php, then i add into composer.json and do dump-autoload they now work. – Elliot Yap Jun 26 '14 at 02:12
0

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

Community
  • 1
  • 1
Andrew E
  • 158
  • 2
  • 4