An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# zframework
[![Star Count](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Star&query=stargazers_count&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fhelloakn%2Fzframework)](https://github.com/helloakn/zframework) [![Licence](https://img.shields.io/badge/dynamic/json?color=informational&label=LICENCE&query=license.name&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fhelloakn%2Fzframework)](https://github.com/helloakn/zframework) [![Language](https://img.shields.io/badge/dynamic/json?color=blueviolet&label=Language&query=language&url=https%3A%2F%2Fapi.github.com%2Frepos%2Fhelloakn%2Fzframework)](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;
}
}
}
?>
```

- - -