PHP code example of braune-digital / api-base-bundle
1. Go to this page and download the library: Download braune-digital/api-base-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
braune-digital / api-base-bundle example snippets
public function registerBundles()
{
$bundles = array(
...
new JMS\SerializerBundle\JMSSerializerBundle(),
new FOS\RestBundle\FOSRestBundle(),
new BrauneDigital\ApiBaseBundle\BrauneDigitalApiBaseBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
...
);
namespace BrauneDigital\DemoBundle\Controller\V1;
use BrauneDigital\ApiBaseBundle\Controller\BaseApiController;
use BrauneDigital\DemoBundle\Form\Type\ProjectType;
use BrauneDigital\Pitcher\BaseBundle\Entity\Company;
use BrauneDigital\Pitcher\BaseBundle\Entity\Project;
use Doctrine\Common\Collections\ArrayCollection;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
/**
* @author Patrick Rathje <[email protected]>
* @copyright 2016 Braune Digital GmbH
*/
class ProjectController extends BaseApiController {
protected function getRepository() {
return $this->getDoctrine()->getRepository('BrauneDigitalDemoBundle:Project');
}
/**
*
* @ApiDoc(
* resource=false,
* section="Project",
* description="Get a project by id",
* "API-Version", " */
public function createAction(Request $request, $entity = null, $refresh = false, $formOptions = null) {
$entity = new Project();
return parent::createAction($request, $entity);
}
/**
*
* @ApiDoc(
* resource=false,
* section="Project",
* description="Update a project",
* * }
*)
*
* @param Request $request
* @param $id
* @return \FOS\RestBundle\View\View
*
* @Rest\Delete("/projects/{id}", name="project_delete", defaults={"_format": "json"})
*/
public function deleteAction(Request $request, $id) {
return parent::deleteAction($request, $id);
}
/**
* Override the getForm Method for create and update functionalities, you may want to return different forms accordings to the mode
**/
protected function getForm($entity, $mode = '', $options = array()) {
return $this->createForm(new ProjectType(), $entity, $options);
}
}
protected $token;
/**
* @return mixed
*/
public function getToken()
{
return $this->token;
}
/**
* @param mixed $token
*/
public function setToken($token)
{
$this->token = $token;
}
use BrauneDigital\ApiBaseBundle\Annotation\ModuleAccess;