Skip to content

hersoncruz/API-REST-PHALCON-PHP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phalcon API Rest

This is a basic API Rest Project based in Apigee Best Practices using the Phalcon PHP Framework (The fastest PHP Framework)

Complete CRUD (Create, Read, Update, Delete) of all tables of your database (including relationships), just point the database and generate models. All communication response/request with JSON.

Example:

GET /user return all users
GET /user/1 return user with id 1
GET /department/1/user return all user belonging the departament with id 1
POST /user insert user
PUT /user/1 update the user with id 1
DELETE /user/1 delete user with id 1
The Search method is in development..

Get Started

From framework installation until your database crud

  1. Install Phalcon Framework

  2. Install Phalcon Developer Tools - This is a dev tools helpful for phalcon php developers

  3. Clone the project for your machine

    git clone https://github.com/edvaldoribeiro/API-REST-PHALCON-PHP.git

  4. Remove the examples of controllers and models.

app/controllers/UserController.php
app/controllers/DepartamentController.php
app/models/User.php
app/models/Department.php

DB example used for tests /example.sql

  1. Set the access configuration of your database in app/config/config.php

     'database' => array(
         'adapter'     => 'Mysql',` 
         'host'        => 'localhost',
         'username'    => 'root',
         'password'    => 'root',  
         'dbname'      => 'example',
     ) 
    
  2. Within the project execute the follow command (with phalcon dev tools) for export your database in models

phalcon --all-models

For the relationships works well your tables need to be setted with relationships correted. In my dev tools version the relationships are not being mapped in models just with command line above. To fix this, after you run the command above just open http://localhost/API-REST-PHALCON-PHP/webtools.php (case error, alter path of devtols in public/webtools.config.php), select the option all in "Table name" and mark the cheboxes "Define Relations", "Force" and click generate. All of your models will be updated with relationships.
  1. Now just generate the empty controllers with same name of models, like the example below, using phalcon dev tools:

    phalcon controller User --base-class=RestController
    phalcon controller Department --base-class=RestController

    It's very important use the param --base-class to extends the RestController, because all crud are in there. If you need create another response for any part of your crud, just implement the action in desired controller overriding the RestController method.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 79.6%
  • CSS 18.2%
  • ApacheConf 1.2%
  • HTML 1.0%