Installation
Add the package to your composer.json under require:
"ais/daftarbundle": "dev-master"
Run composer update.
Register the Bundle
Add Ais\DaftarBundle\AisDaftarBundle() to your AppKernel.php under registerBundles().
Ensure NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle are also registered.
Configure Routing
Add the following to app/config/routing.yml:
ais_daftars:
type: rest
prefix: /api
resource: "@AisDaftarBundle/Resources/config/routes.yml"
NelmioApiDocBundle:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /api/doc
First Use Case
Access the API documentation at http://localhost/web/app_dev.php/api/doc to explore available endpoints.
API-Driven Development
Leverage NelmioApiDocBundle for interactive API documentation. Use the generated Swagger UI to test endpoints before full implementation.
RESTful Resource Handling
The bundle integrates with FOSRestBundle and WillDurand/RestExtraBundle, enabling standardized RESTful resource handling. Follow these patterns:
@Rest\Route annotations for controller methods.get, post, put, delete methods for CRUD operations.use FOS\RestBundle\Controller\Annotations\Route;
use FOS\RestBundle\Controller\Annotations\NamePrefix;
class DaftarController extends FOS\RestBundle\Controller\FOSRestController
{
/**
* @Route("/daftars", name="get_daftars")
* @NamePrefix("api_")
*/
public function getDaftarsAction()
{
return $this->handleView($this->get('daftar.manager')->findAll());
}
}
Serialization with JMS
Use JMSSerializerBundle to serialize/deserialize Daftar entities. Configure metadata in config/serializer/Mapping/Daftar.config.yml:
Ais\DaftarBundle\Entity\Daftar:
exclusion_policy: ALL
properties:
id:
expose: true
type: integer
name:
expose: true
type: string
Dependency Injection
Inject services like daftar.manager (assumed) into controllers or services:
public function __construct(Ais\DaftarBundle\Manager\DaftarManager $daftarManager)
{
$this->daftarManager = $daftarManager;
}
Form Handling Use Symfony forms for input validation. Example:
$form = $this->createFormBuilder($daftar)
->add('name', 'text')
->getForm();
Symfony Version Mismatch The bundle is designed for Symfony 2.7.4. Using it with newer versions (e.g., 3.x or 4.x) may cause compatibility issues. Test thoroughly or fork the bundle.
Missing Dependencies
The bundle requires NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle. Forgetting to register these will break routing or serialization.
Dev-Master Dependency
The package is installed from dev-master. Avoid using this in production without pinning a stable version (e.g., "ais/daftarbundle": "1.0.0").
Undocumented Features
The bundle lacks clear documentation. Inspect AisDaftarBundle/Resources/config/routes.yml and AisDaftarBundle/Entity/ for clues about available endpoints/entities.
Email for Support
Issues or PRs should be emailed to vizzlearn@gmail.com. GitHub issues may not be monitored.
Check Routes
Run php app/console debug:router to verify routes are loaded. Missing routes often indicate misconfigured routing.yml.
Enable Profiler
Use Symfony’s profiler (/app_dev.php/_profiler) to debug requests, especially for serialization errors or missing services.
Validate Entities If forms or API requests fail, validate entities manually:
$errors = $this->get('validator')->validate($daftar);
if (count($errors) > 0) {
throw new \RuntimeException((string) $errors);
}
Log Serialization Issues
Enable JMS serializer logging in config.yml:
jms_serializer:
metadata:
debug: %kernel.debug%
Custom Controllers
Extend or override bundle controllers by creating your own in src/Acme/DaftarBundle/Controller/ and configuring routes to prioritize them.
Entity Extensions
Extend Ais\DaftarBundle\Entity\Daftar to add custom fields or behaviors:
namespace Acme\DaftarBundle\Entity;
use Ais\DaftarBundle\Entity\Daftar as BaseDaftar;
class Daftar extends BaseDaftar
{
/**
* @ORM\Column(type="string")
*/
private $customField;
}
Event Listeners
Subscribe to bundle events (if any) via services.yml:
services:
acme.daftar.listener:
class: Acme\DaftarBundle\EventListener\DaftarListener
tags:
- { name: kernel.event_listener, event: daftar.pre_save, method: onPreSave }
Override Templates
Override bundle templates by placing them in app/Resources/AisDaftarBundle/views/. Example: app/Resources/AisDaftarBundle/views/Default/index.html.twig.
Custom Managers Create a custom manager by extending the bundle’s manager and injecting it via DI:
services:
acme.daftar.manager:
class: Acme\DaftarBundle\Manager\DaftarManager
parent: ais.daftar.manager
How can I help you explore Laravel packages today?