amivag
amivag

Reputation: 91

Rendering custom PHP code [UserFrosting/Slim]

[UserFrosting 0.3.1]

I want to execute a custom PHP file, bypassing other UserFrosting architecture.

Slim's $app->render("myfile.php") does not seem to work. It expects a twig file in the themes directory, it won't execute a PHP script.

How do I bypass this limitation?

Detailed information on what I am trying to achieve:

I have made a file-upload script in a custom PHP file. It uses the $_FILESarray, POSTed from a user form (from UserFrosting dashboard), to handle user file uploads and do some processing work.

I have not managed to get access to $_FILES data through a custom UserFrosting's controller class. Which is why I used a plain old external PHP file in root directory, and it works.

Now I am looking to route to that PHP file through Slim, to enforce basic user authentication/permissions.

Upvotes: 2

Views: 456

Answers (1)

alexw
alexw

Reputation: 8688

In general, I would recommend against this approach for designing an application that will be easy to manage in the long term. $_FILES is a superglobal, and so should be accessible from anywhere - even from within a class method. So, I'm not sure why you would have trouble accessing it in your controller.

However, if you really need to invoke a standalone PHP file containing procedural code, you can always use a plain old include from within a route closure:

$app->get('/my-route/?', function () use ($app) {    

    // Access-controlled page
    if (!$app->user->checkAccess('uri_my_route')) {
        $app->notFound();
    }

    include "path/to/myfile.php";
});

Upvotes: 2

Related Questions