The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

I am a beginner with MVC, and i need to learn how to do MVC with Slim

Garrett Morris's Avatar

Garrett Morris

06 Oct, 2014 09:18 PM

This is an example of what i got so far. write now it just generates an ad and takes some request parameters, then replaces the #CODE# segments with the content and echos the html. I do not understand much about MVC really. I want to understand what i need to do to render a dynamic view with view controllers, as i am now just reading the static html page for a route and injecting it into the content. could anyone give a mvc noob some pointers?

specifically, one of my view controllers might require some parameters to be passed. how do i go about handling this?

I have been building non mvc apps for along time and have developed a pretty deep library of classes and objects, and i'm tired of writing procedural code and having hundreds of files in the document root (for each page)

this is example of what i'm doing. can someone show how i might be able to call my view file, pass it some parameters and have it rendered with the Slim\Slim::render() method?
```php $base = '';//no trailing slash

$uploads = ''; 

$app = new \Slim\Slim();

$ad = getRandAd();

$menu = menu();

$template = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'views'. DIRECTORY_SEPARATOR .'template.html');

$app->get('/',function() use($base,$app,$menu,$template){

    $seo = 'keywords';
    $title = 'title';
    $desc = 'description';
    $img   = $base.'/assets/img/logo2.png';
    $url   = $base.$app->request()->getPath();
    $content = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'views'. DIRECTORY_SEPARATOR .'home.html');
    $search = ['#AD#','#SEO#','#TITLE#','#IMG#','#DESC#','#URL#','#MENU#','#CONTENT#'];
    $replace = [$ad,$seo,$title,$img,$desc,$url,$menu,$content];
    $html =  str_replace($search,$replace,$template);
    echo $html;


  1. 1 Posted by blhopwood on 27 Oct, 2015 03:56 AM

    blhopwood's Avatar

    you can see CodeCourse's examples on YouTube:

    check out the How to do MVC and the PHP authentication videos.

  2. 2 Posted by James Avakian on 29 Oct, 2015 07:03 PM

    James Avakian's Avatar

    I am looking to write an API for Swift iPhone secure access by JSON using SwiftySon and Slim. Can you recommend any references of the docket to research for development ?

    Thank you,

    James Avakian, iOS Mobile Developer
    Optical Automation, LLC

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


? 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