cklester's avatar

How To Include a PHP File in Laravel Controller Source

I'm trying to integrate this code into a CommunityController.php file, but this line doesn't work for me:

require_once dirname(__FILE__).'/forum_sso_functions.php';

How do I form that require_once call so it works from my controller?

0 likes
8 replies
jlrdw's avatar

Where did you place the file? Just put it where you can require it more easily.

Just example, but in controllers folder, make new folder named 'yourchioce' and

require_once controllers/yourchoice/forum_sso_functions.php';

Just an example, but there is no way to namespace it and make a use statement? I'd try that first.

cklester's avatar

Hi, @jlrdw , I did try this path:

require_once '/resources/views/pages/forum_sso_functions.php';

but that returns this error:

FatalErrorException in CommunityController.php line 5:
main(): Failed opening required '/resources/views/pages/forum_sso_functions.php' (include_path='C:\xampp\php\PEAR')
jlrdw's avatar

Try a folder under Controllers, that way the path is right there.

willvincent's avatar

@jlrdw It's procedural code. Not even remotely OO..

It could probably be wrapped up in a class, and there's really so little code involved it would probably make sense to simply copy/paste it into a class that can be autoloaded.

Based on the quality of the code though, I'd seriously question whether or not to use this service at all. They have several other repos for various other languages, none of which have any code. Makes me think the service is probably somewhat poorly implemented in php and while they intended to provide SSO libraries for it in other languages (.net, java, python, etc) they haven't gotten around to doing so in 4+ years.

Maybe it's just me, but that doesn't inspire a lot of confidence for me.

cklester's avatar

@willvincent I've been searching and looking for a good forum to integrate with my site, and I'm still testing a few. Do you have any suggestions?

cklester's avatar

If I had started building my own weeks ago instead of trying to integrate an existing product, I'd probably be done with it by now.

fml

Hey! That series isn't even finished! X)

Please or to participate in this conversation.