Coder Social home page Coder Social logo

slimmvc's Introduction

SlimMVC

SlimMVC is the easiest and flexible way to create your PHP application using a MVC pattern. SlimMVC use the PHP microframework Slim Framework and use the best practices collected in the slim community.

Getting Started

  1. Get or download the project
  2. Install it using Composer

Folder System

  • lib/
    • Config.php (Class to store with config variables)
    • Core.php (Singleton PDO connection to the DB)
  • models/
  • public/
  • routers/
    • name.router.php (routes by functionalities)
  • templates/

lib/

Here we have the core classes of the connection with the DB

models/

Add the model classes here. We are using PDO for the Database.

Example of class:

Stuff.php

class Stuff {

    protected $core;

    function __construct() {
        $this->core = Core::getInstance();
    }

    // Get all stuff
    public function getAllStuff() {
        $r = array();

        $sql = "SELECT * FROM stuff";
        $stmt = $this->core->dbh->prepare($sql);

        if ($stmt->execute()) {
            $r = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        } else {
            $r = 0;
        }
        return $r;
    }
}

public/

All the public files:

  • Images, CSS and JS files
  • index.php

routers/

All the files with the routes. Each file contents the routes of an specific functionality. It is very important that the names of the files inside this folder follow this pattern: name.router.php

Example of router file:

stuff.router.php

// Get stuff
$app->get('/stuff', function () use ($app) {
    echo 'This is a GET route';
});

//Create user
$app->post('/stuff', function () use ($app) {
    echo 'This is a POST route';
});

// PUT route
$app->put('/stuff', function () {
    echo 'This is a PUT route';
});

// DELETE route
$app->delete('/stuff', function () {
    echo 'This is a DELETE route';
});

templates/

All the Twig templates.

How to Contribute

Pull Requests

  1. Fork the SlimMVC repository
  2. Create a new branch for each feature or improvement
  3. Send a pull request from each feature branch to the develop branch

slimmvc's People

Contributors

larkarvin avatar revuls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slimmvc's Issues

global objects

SlimMVC/lib/Core.php

For example if I want to use PHPMailler same way as PDO where should I add it? in core.php file or do I need to create another file and use same cade with different names? or is it a good idea to use like PDO?

Thanks.

Error with PDO

Good Day,

as excelent resource to work with slim, i made one change, in lib\core for using pdo

[code]
try {
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
[/code]

then i change config data and try to work with my own database, so i´ve error trying using stuff with getAllStuff function on

[code]
$stmt = $this->core->dbh->prepare($sql);
[/code]

the function "prepare" is not accesible from this instance, also i think is a little bug in the __construct function when make lib\core accesible in the $this->core var to get pdo options. But thanks, this is a great an amazing project

slim application error

lib\Config not found error

Fatal error: Class 'lib\Config' not found in /var/www/devdomain.dev/config.php on line 6

Hi i'm getting this error. Why do you think it's the problem?

Thanks.

edit: never mind I needed to update my composer because I implemented your code to mine.

PDO Exception

Getting this error " Call to undefined method PDOStatement::excute()" while invoking this " $stmt = $this->core->dbh->prepare($sql);" in Models:user.php.

Slim2

Hello is this based on Slim 2?

I would like to install Slim with Composer. But this is manually installed. How would it change?

How to run with Built in Server?

Hi!

I'm not an expert in PHP but I like how this is very similar to what I use with express.js.

I am having trouble running this by doing the following in bash:

EDIT: I updated this to what my actual problem was, not after retrying without using composer to install the deps...

git clone https://github.com/revuls/SlimMVC.git .
composer install
php -S localhost:8000

If I open my browser to http://localhost:8000/public/index.php I get

::1:53704 [500]: /public/index.php - Call to undefined method Slim\Views\Twig::all() in /var/www/app/vendor/slim/views/Slim/Views/Twig.php on line 88

Any ideas?

User autentication

Hi man!

Is it possible to add user autentication??

thank you for your wonderful work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.