PHP micro-framework that built upon MVC workflow .
-
Install XAMPP on your local machine. (Optional)
-
Start Apache server and MySQL database server from XAMPP. (Optional)
-
Navigate to xampp\htdocs from your command line then enter:
git clone https://github.com/IslamAliMuhammad/PHP-MVC-FRAMEWORK.git
-
Enter
localhost/{Apace server port}/PHP-MVC-FRAMEWORK
to your browser.
- 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
- inc
- pages
- public
- css
- index.php This is the main file loaded which will load bootstrap.php and inistatiate Core.php.
- js
POST-APP you can use this project as a reference to use the framework.
- Change the root folder with your desire name.
- Navigate to app/config/config.php and input your configurations.
- Navigate to the public folder, select .htaccess file and in RewriteBase /PHP-MVC-FRAMEWORK/public change /PHP-MVC-FRAMEWORK/ to your root folder name.
- Instantiate the model you created inside corresponding controller constructor throw model($model) method which is part of the Controller base class.
- Create a models folder inside the app folder.
- Create your model inside the models folder.
- 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.
Method Signature:
query($sql)
- Prepare SQL statement.
- $sql:
<String>
sql prepared statement
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.
Method Signature:
execute()
- Return true if prepared statement execution is successful false other wise.
Method Signature:
resultSet()
- Return array of objects represent rows as results (include internal execute() function call)
Method Signature:
single()
- Return single object represent single row as result (include internal execute() function call)
Method Signature:
rowCount()
- Return number of rows affected by the last SQL statement
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.
- Navigate to the app/controller create a new file that represents a new controller (any controller needs to extend base Controller class).
- Navigate to app/views and create a new folder that represents views for the controller was created
- 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).
- Create a method inside the controller was created that method responsible for instantiating model and load the view with data get from model.