Can i combine Slim with plain PHP

Hi!
I just started with PHP not too long ago and have done some small projects with just plain PHP + Ajax + html.
I’m more comfortable with procedural code than OOP. I can still use OOP library of Pakagist. But i want to go slow the first time using a framework.

I want to do a serious new project with Slim but in a procedural way.
My ideas:

  • Only use routing to require a view
  • My Url: example.com/?r={child router}&page={view}
  • Routing: Only used to require to a child router and forward $parameter.
  • Template & View: will receive a json result from ajax callback, my app will heavy ajax.
$app->get('/}', function() {
    require "index.view";
});
$app->get('/{route}/{page}', function (Request $request, Response $response, array $args) {
    $route = $args['route'] ? $args['route'] : "";
    $page = $args['page'] ? $args['page'] : "";
// I have a folder View contains folder User
    if folder_exists("route/" . $route)
    {
        if file_exists("view/" . $route . "/" . $page . ".php")
        {
            require ("view/" . $route . "/" . $page . ".php");
        } else {
            require ("view/" . $route . "/def_page.php");
        }
    } else {
      header (Location: index.php);
    }
});


// example.com/?r=user&page=register
// will require view/user/register.php

// example.com/?r=admin&page=login
// will require view/admin/login.php

And all my logic will be handled through an ajax route like

$app->get('/ajax/{route}/{action}', function (Request $request, Response $response, array $args) {
    $route = $args['route'] ? $args['route'] : "";
    $action= $args['action'] ? $args['action'] : "";
// I have a folder View contains folder User
    
        if file_exists("ajax/" . $route . "/" . $page . ".php")
        {
            require ("ajax/" . $route . "/" . $page . ".php");
        } else {
            $result = [
                        'status' => false,
                        'msg' => 'failed'
            ]
            return json_encode($result);
        }
});

// example.com/?r=ajax&action=login
// will require ajax/user/login.php

Please help me and let me know if this doesn’t fit in Slim or anything bad.
Thanks for help.

… I want to do a serious new project with Slim but in a procedural way.

Don’t.
Especially if it is supposed to be serious - by the way, what do you mean serious?

It is not a good sign if you let your limitations to force you to do things in a wrong way.
If you want to do something, do it right, at least try.

1 Like