0

I am using the Laravel 4 framework, and I am trying to set up the Facebook authentication system. I have an authentication system I had set up on another site (not using a framework) that used a config.php and process_facebook.php file. I am trying to implement this config.php file into my views. So far, I am including the files in a folder called "includes", within my "app" folder. I am trying to use the following code to implement it:

$app = app();
include($app['path.app'].'/includes/config.php');

My question is, where in the view do I put this code? Do I have to use php tags? (I am using the blad functionality). Your help is appreciated.

3
  • Instead of working an old script into L4 perhaps look to migrate the facebook auth? packagist.org/search/?q=facebook%20auth Commented Jun 18, 2013 at 7:31
  • 1
    Do not put such logic in your views but instead in a controller or another "model-like" class. Commented Jun 18, 2013 at 9:58
  • How did you deal with this issue ? Don't forget to say what solution you choose finally or, at least, accept an answer to close the question if you don't need more explanation. This is important to lead the next viewers to the right way. Commented Jul 1, 2013 at 15:11

2 Answers 2

2

Laravel is an MVC framework, the purpose is to organise your code and clean your views. So this shouldn't be in your view.

I think the best way should be :

  1. Create a facebook.php file in the config folder wich contains all your facebook configuration (read http://laravel.com/docs/configuration)
  2. Create a folder named services, helpers or includes (as you want) and put process_facebook.php inside (I bet it contains the methods to deal with facebook API).
  3. Add two lines of configuration to include this new folder

Like that :

// composer.json
"autoload": {
    "classmap": [
        [...]
        "app/services",
    ]
},

// start/global.php
ClassLoader::addDirectories(array(
    [...]
    app_path().'/services',
));

Then, you can use your facebook class or methods all over your app.

Sign up to request clarification or add additional context in comments.

Comments

0

The route you are taking to include configuration files is not recommended, but it is possible. Please see information about Laravel Configuration Files.

You should be able to use the following in your view:

<?php include(app_path().'/includes/config.php'); ?>

As it is a configuration file, it would be better to use require() instead of include(). In addition, it would also be better to include the file in the necessary controller(s).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.