Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpiazzal/mvc-php
A basic PHP Model View Controller to create your own framework or app from scratch.
https://github.com/jpiazzal/mvc-php
Last synced: 13 days ago
JSON representation
A basic PHP Model View Controller to create your own framework or app from scratch.
- Host: GitHub
- URL: https://github.com/jpiazzal/mvc-php
- Owner: jpiazzal
- License: mit
- Created: 2019-02-11T11:06:11.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-11T13:46:15.000Z (almost 6 years ago)
- Last Synced: 2024-11-11T11:51:33.005Z (2 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mvc-php
A basic PHP Model View Controller to create your own framework or app from scratch.## Table of Contents
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)## Usage
### Front End
If you want to keep Boostrap, a quick start [here](https://getbootstrap.com/docs/4.2/getting-started/introduction/).
To use others frameworks or update the front end, everything you need is in the folder `app/views/`.
Add css and js in the folders `public/css/` and `public/js/`.
`style.css` and `script.js` already exist and are included in `app/views/layout.php`.### Back End
#### Run the framework
Initialization, autloading and routing are made in `core/Router.php`.
To use it, require the file `Router.php` and run the framework in your `index.php`:
```php
**/!\ Use the syntax** `XxxModel` **for the name of the file and the class (case sensitive).**
Do not require your file, autoloading do it for you.All models classes must extends from the class Model in `core/Model.php`.
Example: `app/models/ExampleModel.php`
```php
**/!\ Use the syntax** `XxxController` **for the name of the file and the class (case sensitive).**
Do not require your file, autoloading do it for you.All controllers classes must extends from the class Controller in `core/Controller.php`.
Example: `app/controllers/home/IndexController.php`
```php
In the example: `app/controllers/home/` and `app/views/home/`.
Default value: `home`.- `c` is the **Controller** used.
In the example `index` for `app/controllers/home/IndexController.php`.
Default value: `index`.- `a` is the **Action** asked to the controller. It choose the right view.
In the example, `index` is a method of `IndexController`.
The name of the view is `index.php` in `app/views/home/index.php`.
Default value: `index`.### Database
Database calls are made in `core/Mysql.php`.
Database configuration is in `config/config.php`.
Differents uses of `Mysql` instance in a model class, `$this->db` is instantiate in the constructor in `Model` class:
```php
query("SELECT title from news WHERE id = 1");
$result = $db->query("SELECT title from news WHERE id = ? AND author_id = ?", array("1", "1"));
$result = $db->query("SELECT title from news WHERE id = :id", array("id" => "1"));
}}
````$result`:
```php
Array
(
[0] => Array
(
[title] => "My Title"
)
)
````WHERE IN` is not supported for now.
## License
*mvc-php* is [licensed](https://github.com/jpiazzal/mvc-php/blob/master/LICENSE) under the MIT license.