Ichi PHP MVC Framework

Installs: 15

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:project

1 2024-02-24 07:17 UTC

This package is auto-updated.

Last update: 2024-05-06 15:41:36 UTC


README

ICHI PHP FRAMEWORK is the fast and secure MVC PHP framework.

License

This framework is Open Source According to MIT license

Table Of Contents

Installation

composer create-project jijihohococo/ichi:dev-master your_project

Setup

First, You must create .env file under your project folder. And then you must declare your real database name, database username and password in this .env file.

You can see how to set the data in .env.example under your project folder.

In your .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user_name
DB_PASSWORD=your_database_password

You can run the app from public path

your_project/public > php -S localhost:8000

Using

Route

You can add your route in 'web' function of "routes/web.php".

If you want to add another route file, create new route file under "routes" folder. And then you must add new function like 'web.php'.

function new_routes($route){

}

Then you must use your new route file in 'app/Kernel.php';

namespace App;

use JiJiHoHoCoCo\IchiRoute\Router\Route;

require_once __DIR__ . '/../routes/new_routes.php';

class Kernel{


	public function run(){
		$route=new Route;
		new_routes($route);
		$route->run();
	}



}

Above code is highlighting the things in adding new route file.

You can use this docuementation for the route functions in detail.

Middleware

You can create middleware for routes in command line.

php ichi make:middleware NewMiddleware

The Middleware Class will be created under 'app/Middleware' folder.

You can use this documentation for the middleware functions in detail.

Model

You can add another database connection in "app/Kernel.php" as shown as this documention .

You can create model in command line.

php ichi make:model NewModel

The Model Class will be created under 'app/Models' folder.

Example Model

namespace App\Models;

use JiJiHoHoCoCo\IchiORM\Database\Model;

class NewModel extends Model{

	public $id , $name , $created_at , $updated_at , $deleted_at ;

}

You can use this documentation to use Model in detail

Controller

You can create Controller in command line.

php ichi make:controller NewController

The Controller Class will be created under 'app/Controllers' folder.

For more detail, use this documentation .

View

You can create View Component Class in command line.

php ichi make:component ViewComponent

The View Component Class will be created under 'app/Components' folder

You can return view in the route or controller's function

Without Controller

$route->get('/welcome',function(){
	return view('welcome.php');
});

With Controller

$route->get('/welcome','HomeController@welcome');
namespace App\Controllers;


class HomeController{


	public function welcome(){
		return view('welcome.php');
	}


}

You must create view PHP file under 'resources/views' folder.

For more detail, use this documentation.

Validation

You can validate the input data in your controller class

namespace App\Controllers;


use JiJiHoHoCoCo\IchiValidation\Validator;
class TestController{


	public function test(){

		$validator=new Validator();
		if(!$validator->validate($_REQUEST,[
			'name' => 'required' ,
			'age' => 'required|integer' ,
			'email' => ['required','email']
		])){
			setErrors($validator->getErrors());
			return view('test.php');
		}

	}


}

You can call your validation error messages in your view php file


<?php if(isset($errors['name'])): ?>
<?php echo $errors['name']; ?>
<?php endif; ?>

For more detail, use this documentation.