Skip to content

Instantly share code, notes, and snippets.

@teddy-hoo
Created May 5, 2017 04:14
Show Gist options
  • Select an option

  • Save teddy-hoo/9e006c8e0020dce2b9c8781b0d6ecec3 to your computer and use it in GitHub Desktop.

Select an option

Save teddy-hoo/9e006c8e0020dce2b9c8781b0d6ecec3 to your computer and use it in GitHub Desktop.
php oop in a typical web application
<?php
/**
* basic model
*/
class Model {
protected $connection = 'db';
public static
}
/**
* order model
*/
class Order extends Model {
protected $fields = [
'id',
'money',
];
public function create ($data) {
// create row in db ...
$id = 1111;
return $id;
}
}
/**
* order business logic
*/
class OrderService {
public function validateParams ($params) {
// validation logic ...
}
public function createOrder ($params) {
$this->validateParams($params);
return (new Order())->create($params);
}
}
/**
* basic controller
*/
class BaseController {
protected function getPostParams () {
return $_POST;
}
}
/**
* order controller
*/
class OrderController extends BaseController {
public function createAction() {
$params = $this->getPostParams();
$orderService = new OrderService();
$result = $orderService->createOrder($params);
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment