Git Product home page Git Product logo

php-mvc-micro-framework's Introduction

PHP MVC micro-framework

PHP micro-framework that built upon MVC workflow .

Getting Started

Installing

  1. Install XAMPP on your local machine. (Optional)

  2. Start Apache server and MySQL database server from XAMPP. (Optional)

  3. Navigate to xampp\htdocs from your command line then enter:

    git clone https://github.com/IslamAliMuhammad/PHP-MVC-FRAMEWORK.git
    
  4. Enter localhost/{Apace server port}/PHP-MVC-FRAMEWORK to your browser.

Files structure

  • PHP-MVC-FRAMEWORK
    • README.md
    • app
      • bootstrap.php Contain files needed to initially loaded.
      • config
      • controllers
        • Pages.php The default controller contains the index() method which is the default method.
      • libraries
        • Controller.php Base class of controllers which has two methods:

          • model($model) Instantiate model we pass to.
          • view($view, $data = []) load view we pass to along with data we need to inject to the view.
        • Core.php Extract controller, method, params from URL then load the controller and execute the method with the params.

        • Database.php Database Class which use PDO to establish a connection and interact with the database.

      • views
    • public

Start building upon the framework

Project as a guide

POST-APP you can use this project as a reference to use the framework.

Configure your app

  1. Change the root folder with your desire name.
  2. Navigate to app/config/config.php and input your configurations.
  3. Navigate to the public folder, select .htaccess file and in RewriteBase /PHP-MVC-FRAMEWORK/public change /PHP-MVC-FRAMEWORK/ to your root folder name.
  4. Instantiate the model you created inside corresponding controller constructor throw model($model) method which is part of the Controller base class.

Utilize your database

  1. Create a models folder inside the app folder.
  2. Create your model inside the models folder.
  3. Instantiate Database class in the model constructor which will create a connection with database based on your configurations, then now you can use methods inside Database instance to interact with the database.

query

Method Signature:

query($sql)
  • Prepare SQL statement.
  • $sql: <String> sql prepared statement
bind

Method Signature:

bind($params, $value, $type)
  • Bind values with a prepared statement.
  • $params: <String> parameter in your prepared statement.
  • $value: <String> value will pass to parameter.
  • $type: (optional) default value null type of value you will pass.
execute

Method Signature:

execute()
  • Return true if prepared statement execution is successful false other wise.
resultSet

Method Signature:

resultSet()
  • Return array of objects represent rows as results (include internal execute() function call)
single

Method Signature:

single()
  • Return single object represent single row as result (include internal execute() function call)
rowCount

Method Signature:

rowCount()
  • Return number of rows affected by the last SQL statement

Load view with data

Inside your controller use view method which is part of base Controller class.

view($view, $data = [])
  • $view: <String> path of view inside views folder that will load.
  • $data: <array> data that will pass to the view.

Adding a feature to my app

  1. Navigate to the app/controller create a new file that represents a new controller (any controller needs to extend base Controller class).
  2. Navigate to app/views and create a new folder that represents views for the controller was created
  3. Navigate to the app/model create a new model class that handles database (model class must instantiate Database library to interact with the database through the Database library that interacts with the actual database through PDO).
  4. Create a method inside the controller was created that method responsible for instantiating model and load the view with data get from model.

php-mvc-micro-framework's People

Contributors

islamalimuhammad avatar

Watchers

 avatar

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.