The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

How to add a functions.php

legomolina's Avatar

legomolina

27 Jul, 2015 10:43 AM

Hi, I have next dir tree:
/www/mysite : -index.php -.htaccess

/www/mysite/public_html/Views : -home.php

/www/mysite/public_html/Scripts : -functions.php

How can I call a function from home.php. I tried <?php myFunction(); ?> but it doesn't work. I have imported functions.php to index.php, is it correct?
Thank you :D

  1. Support Staff 1 Posted by Andrew Smith on 29 Jul, 2015 10:29 AM

    Andrew Smith's Avatar

    This is not part of Slim itself, you would need to include that file at the top of index.php in order to make use of the functions.

  2. 2 Posted by legomolina on 29 Jul, 2015 11:43 AM

    legomolina's Avatar

    Hi, I include the file at the top of index.php but it doesn't work.

    <?php
    include "var/www/mysite/public_html/Scripts/Php/passwordHash.php";

    require 'Slim/Slim.php';
    \Slim\Slim::registerAutoloader();

    $projectDir = '/var/www/mysite/public_html';

    $app = new \Slim\Slim(array(
        'templates.path' => '/var/www/mysite/public_html/Views'
    ));

    require "$projectDir/routes.php";
    require "$projectDir/includes.php";

    $app->run();

    If I open the file where I call the function an error appears in console:
    GET http://localhost/mysite/pass 500 (Internal Server Error)

    But if I omit the function calling, this error doesn't appear.
    What I'm doing wrong? Thank you

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac