Install Dependencies
Add to composer.json:
"require": {
"ais/bimbinganbundle": "dev-master",
"nelmio/api-doc-bundle": "^3.0",
"fos/rest-bundle": "^2.0",
"jms/serializer-bundle": "^1.0"
}
Run:
composer update
Register Bundles
Update AppKernel.php:
public function registerBundles()
{
return [
// ...
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Ais\BimbinganBundle\AisBimbinganBundle(),
];
}
Configure Routing
Add to app/config/routing.yml:
ais_bimbingans:
type: rest
prefix: /api
resource: "@AisBimbinganBundle/Resources/config/routes.yml"
Verify API Docs Access:
http://localhost/api/doc
The bundle provides RESTful endpoints for "Bimbingan" (guidance/counseling) entities. Start by testing the API endpoints:
GET /api/bimbingansPOST /api/bimbingans (with JSON payload)GET /api/bimbingans/{id}Customize the Entity
Extend the base Bimbingan entity (located in Ais/BimbinganBundle/Entity/Bimbingan.php):
namespace App\Entity;
use Ais\BimbinganBundle\Entity\Bimbingan as BaseBimbingan;
class Bimbingan extends BaseBimbingan
{
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
}
Override Services
Use dependency injection to replace the default BimbinganService:
# app/config/services.yml
services:
app.bimbingan.service:
class: App\Service\CustomBimbinganService
arguments: ["@doctrine.orm.entity_manager"]
Customize Serialization
Extend the serializer configuration in config.yml:
jms_serializer:
metadata:
directories:
App:
namespace_prefix: "App\\Serializer"
path: "%kernel.root_dir%/Serializer"
Doctrine ORM: The bundle uses Doctrine for persistence. Configure relationships in your Bimbingan entity:
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="bimbingans")
*/
private $user;
Validation: Add validation constraints to the entity:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\NotBlank()
* @Assert\Length(min=10)
*/
private $content;
Event Listeners: Subscribe to lifecycle events (e.g., prePersist):
namespace App\EventListener;
use Ais\BimbinganBundle\Entity\Bimbingan;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
class BimbinganListener implements EventSubscriber
{
public function prePersist(LifecycleEventArgs $args)
{
$bimbingan = $args->getEntity();
if ($bimbingan instanceof Bimbingan) {
$bimbingan->setCreatedAt(new \DateTime());
}
}
}
Symfony Version Mismatch The bundle is built for Symfony 2.7. Using it with Symfony 3+ or 4+ may require:
willdurand/rest-extra-bundle is outdated).FOSRestBundle v3+).NelmioApiDocBundle Dependency
The API docs will not render without NelmioApiDocBundle. Ensure it’s registered and configured:
nelmio_api_doc:
areas: # to filter documented areas
default:
path_patterns: ["^/api"]
JMS Serializer Conflicts If you encounter serialization errors, explicitly configure the bundle’s serializer mappings:
jms_serializer:
handlers:
Ais\BimbinganBundle\Entity\Bimbingan:
default_operation_name: "serialization"
directory: "%kernel.root_dir%/Serializer/Bimbingan"
Check Routes Dump available routes to verify the bundle’s endpoints are loaded:
php bin/console debug:router | grep bimbingan
Enable Profiler Use Symfony’s profiler to inspect requests/responses:
// app/config/config_dev.yml
framework:
profiler: { only_exceptions: false }
Log Entities Enable Doctrine logging to debug ORM issues:
doctrine:
dbal:
logging: true
profiling: true
Custom Controllers
Override the default controller by creating a new one and updating routes.yml:
# app/config/routing.yml
app_bimbingan:
type: rest
resource: "@AppBundle/Controller/BimbinganController"
prefix: /api
Add New Fields
Extend the Bimbingan entity and update the serializer:
// src/Serializer/BimbinganHandler.php
namespace App\Serializer;
use JMS\Serializer\Context;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
class BimbinganHandler implements SubscribingHandlerInterface
{
public static function getSubscribingMethods()
{
return [
[
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'json',
'type' => 'App\Entity\Bimbingan',
'method' => 'serializeToJson',
],
];
}
public function serializeToJson(Bimbingan $bimbingan, $format, Context $context)
{
return [
'id' => $bimbingan->getId(),
'customField' => $bimbingan->getCustomField(),
];
}
}
Add Custom Actions
Extend the bundle’s BimbinganController:
namespace App\Controller;
use Ais\BimbinganBundle\Controller\BimbinganController as BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class BimbinganController extends BaseController
{
/**
* @Route("/api/bimbingans/{id}/archive", name="archive_bimbingan")
*/
public function archiveAction($id)
{
$this->get('ais_bimbingan.service')->archive($id);
return new Response('Archived', 200);
}
}
How can I help you explore Laravel packages today?