Skip to content

Instantly share code, notes, and snippets.

function () use ($app) {
$body = $app->request->getJsonRawBody(); // リクエストボディを受け取る
$status = $app
->modelsManager
->executeQuery(
'INSERT INTO App\Models\Empuser (id, firstname, lastname, age) VALUES ' .
'(:id:, :firstname:, :lastname:, :age:) ',
[
'id' => $body->id,
'firstname' => $body->firstname,
{
"id":10,
"firstname":"test1",
"lastname":"test2",
"age":20
}
// オートローダー設定
$loader = new Phalcon\Loader();
$loader->registerNamespaces(
[
'App\Models' => __DIR__ . '/models/',
]
);
$loader->register();
// DB接続情報
$container = new Phalcon\Di\FactoryDefault();
$container->set(
'db',
function () {
return new Phalcon\Db\Adapter\Pdo\Postgresql(
[
'host' => 'localhost',
'port' => 5432,
'username' => 'postgres',
$app
->modelsManager
->executeQuery(
'SELECT * FROM App\Models\Empuser WHERE id = :idxxxx: ',
[
'idxxxx' => $id
]);
echo json_encode($records);
C:.
├─models
└─index.php
create table "public".empuser (
id integer not null
, firstname character varying(60) not null
, lastname character varying(60) not null
, age integer not null
, primary key (id)
);
// add start
$app = new Micro();
$app->delete(
'/api/v2/getData',
function () {
$ret = [
'name' => 'yamada',
'id' => 20
];
echo json_encode($ret);
// add start
$app = new Micro();
$app->put(
'/api/v2/getData',
function () {
$ret = [
'name' => 'yamada',
'id' => 20
];
echo json_encode($ret);
// add start
$app = new Micro();
$app->post(
'/api/v2/getData',
function () {
$ret = [
'name' => 'yamada',
'id' => 20
];
echo json_encode($ret);