https://github.com/helloakn/zframework
My Own PHP Framework. Feel free to use.
https://github.com/helloakn/zframework
mvc my-own-php-framework php-framework
Last synced: 8 months ago
JSON representation
My Own PHP Framework. Feel free to use.
- Host: GitHub
- URL: https://github.com/helloakn/zframework
- Owner: helloakn
- License: mit
- Created: 2021-12-03T03:34:59.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-02T07:30:40.000Z (over 3 years ago)
- Last Synced: 2025-03-24T00:41:30.943Z (9 months ago)
- Topics: mvc, my-own-php-framework, php-framework
- Language: PHP
- Homepage:
- Size: 43 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zframework
[](https://github.com/helloakn/zframework) [](https://github.com/helloakn/zframework) [](https://github.com/helloakn/zframework)
## Create Project
```
php zframework/zote init
```
After init prject, file structure will be
```
[dir] zframework
[]...
[dir] project
[file] .env
[dir] public
[file] index.php
[file] .htaccess
[file] robots.txt
[dir] mobile
[file] User.php
[dir] migration
[file] createUser.php
[dir] controller
[file] userController.php
[file] route.php
```
- - -
## Route
* without controller
* with controller
* route prefix
* route Authorization {with guard}
### Route Example
* Route : without controller
```php
addroute('post','/','',function(){
echo "hello";
});
$route->addroute('post','/direct','',function(){
echo "hello direct";
});
?>
```
* Route : controller
```php
addroute('get','/test','UserController','testFun');
?>
```
* Route : Prefix
```php
routePrefix("/demo",function($route){
/* /demo/d1 */
$route->addroute('get','/d1','DemoController','d1Fun');
/* /demo/d2 */
$route->addroute('get','/d2','DemoController','d2Fun');
//nested route prefix
$route->routePrefix("/dx",function($route){
/* /demo/dx/dx1 */
$route->addroute('get','/dx1','DemoController','dx1Fun');
});
$route->routePrefix("/dy",function($route){
/* /demo/dy/dy1 */
$route->addroute('get','/dy1','DemoController','dy1Fun');
});
});
?>
```
- - -
## Model
* Create Model
* Insert
* Update
* Delete
* Select , Where , Group , Order
### Model Example
* Create Model
```php
```
* Insert
```php
itemId = $request->get('id');
$item->name = "Item One";
$item->save();
}
}
?>
```
* Update
```php
get('id'));
$item->name = "ok";
$item->update();
/* OR */
/* second way */
$item = new Item();
$item->itemId = $request->get('id');
$item->name = "Item One";
$item->update();
return $item;
}
}
?>
```
* Select , Where , Group , Order
```php
get();
//where
$item = Item::select("id",'name')->where("id in (1,2)")->get();
//order by
$item = Item::select("id",'name')->where("id in (1,2)")->orderBy("id desc")->get();
//group by
$item = Item::select("SUM(qty) as quantity",'name')->where("id in (1,2,3,4)")->orderBy("name desc")->groupBy("name")->get();
//getAll
$users = User::select("id","name")->getAll();
foreach($users as $user){
echo "name : ". $user['name'] .'
';
}
//paginate
$users = User::select("id","name")
->paginate($page_at-1,$row_count);
$data = array(
"code" => 200,
"status" => "success",
"message" => "success",
"pagination" => $users->paginate,
"data" => $users->data
);
return $data;
}
}
?>
```
- - -
## Validation
* rule
* single file and multi files validation rule
### Validation Example
* rule
```php
field("name")->max(4,"the name should be under 200 length");
$validator->field("name")->min(2);
$validator->field("address")->min(5)->notNull();
//custom validation rule
$validator->field("address")->custom(function($validator) use ( $request){
if($request->get('address')!="Sanchaung"){
$validator->setError("Custom validation erro");
}
});
});
$v = $validator->validate();
if(!$v){
$data = array(
"status_code" => 400,
"status" => "failed",
"validate"=>$v,
"errors" => $validator->error()
);
return $data;
}
}
}
?>
```
* single file and multi files validation rule
```php
file("profile_image")
->extenstions("jpg","png")
->minetype("image/jpeg","image/png");
//multi files
$validator->files("image")
->extenstions("jpg","png")
->minetype("image/jpeg","image/png");
});
$v = $validator->validate();
if(!$v){
$data = array(
"status_code" => 400,
"status" => "failed",
"validate"=>$v,
"errors" => $validator->error()
);
return $data;
}
}
}
?>
```
- - -