Installation
composer require amstaffix/extjs-bundle
Enable the bundle in AppKernel.php:
new Tpg\ExtjsBundle\TpgExtjsBundle(),
Basic Configuration
Add to config.yml:
tpg_extjs:
entities:
- @YourBundle/Entity/
remoting:
bundles:
- YourBundle
Routing
Include in routing.yml:
tpg_extjs:
resource: "@TpgExtjsBundle/Resources/config/routing.yml"
prefix: /extjs
First Use Case
@Extjs\Model (e.g., Acme\DemoBundle\Entity\Person).<script src="{{ asset('extjs/generateModel.js') }}"></script>
Ext.define('Acme.DemoBundle.Entity.Person', { ... });
Workflow:
@Extjs\Model (e.g., @Extjs\Model @ORM\Entity).generateModel.js in your template to auto-generate ExtJS models from Doctrine entities.extjs_model Twig extension to inject models:
{{ extjs_model(true, 'Acme.DemoBundle.Entity.Person') }}
Integration Tips:
<script src="/extjs/generateModel.js?model[]=Acme.DemoBundle.Entity.Person"></script>
@Extjs\ModelProxy("/api/people")
Workflow:
@Extjs\Annotation\Direct.remoteapi.js to enable ExtJS remoting:<script src="/extjs/remoteapi.js"></script>
Test.testAction({ id: 123, name: "John" });
Request object:
public function testAction(Request $request) {
$id = $request->query->get('id');
}
Integration Tips:
Symfony\Component\HttpFoundation\Request for complex queries.JMS\Serializer for automatic data transformation.Workflow:
php app/console generate:rest:controller --controller AcmeDemoBundle:People --entity AcmeDemoBundle:Person
fos_rest in config.yml:
fos_rest:
service:
serializer: tpg_extjs.serializer
routing_loader:
default_format: json
routing.yml:
acmedemo_api_rest:
resource: "@AcmeDemoBundle/Resources/config/routing.rest.yml"
prefix: /api
type: rest
Integration Tips:
--trait flag to separate generated code from custom logic:
php app/console generate:rest:controller --controller AcmeDemoBundle:People --entity AcmeDemoBundle:Person --trait
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\Groups({"get", "list"})
*/
private $name;
Deprecated Symfony 2.3:
FOSRestBundle Dependency:
FOSRestBundle. Ensure it’s installed and configured:
composer require friendsofsymfony/rest-bundle
tpg_extjs.serializer service if FOSRestBundle isn’t properly configured.Annotation Conflicts:
@Extjs\Model and @Extjs\ModelProxy must be placed on the entity class. Conflicts may arise with other annotations (e.g., @ORM\Table).Model Generation Caching:
generateModel.js may cause performance issues.proxy_cache).Request Parameter Handling:
Request objects must wrap parameters in an array when calling from ExtJS:
// Correct:
Test.action({ param: "value" }); // Maps to $request->query->get('param')
// Incorrect (if action expects Request):
Test.action(param: "value"); // Fails silently or throws errors.
404 on /extjs/generateModel.js:
tpg_extjs route is included in routing.yml and the bundle is enabled.php app/console debug:router | grep extjs to confirm the route exists.Serializer Errors:
JMS\Serializer annotations (e.g., @Type("string")).config.yml:
jms_serializer:
debug: true
ExtJS Console Errors:
Ext namespace or incorrect model paths (e.g., Acme.DemoBundle.Entity.Person vs. Acme/DemoBundle/Entity/Person).Custom Model Transformers:
Tpg\ExtjsBundle\Generator\ModelGenerator to modify generated models (e.g., add custom fields or methods).// src/Acme/ExtjsBundle/DependencyInjection/Compiler/ModelGeneratorPass.php
public function process(ContainerBuilder $container) {
$definition = $container->findDefinition('tpg_extjs.model_generator');
$definition->addMethodCall('setCustomTransformer', [new Callback('acme_extjs.custom_model_transformer')]);
}
Override Remote API Behavior:
Tpg\ExtjsBundle\Generator\RemoteApiGenerator to customize how remote actions are wired to Symfony controllers.Add Custom Serialization Groups:
tpg_extjs.serializer service to include additional groups or metadata:
services:
tpg_extjs.serializer:
class: Tpg\ExtjsBundle\Serializer\ExtjsSerializer
arguments:
- ['@serializer', '@tpg_extjs.metadata_factory']
calls:
- [addGroup, ['custom_group']]
Dynamic Proxy Paths:
// src/Acme/ExtjsBundle/Routing/ProxyPathGenerator.php
public function generateProxyPath(EntityManager $em, string $entityClass): string {
return '/dynamic/api/' . strtolower(class_basename($entityClass));
}
services.yml and override the default proxy path logic.Rapid Prototyping:
generate:rest:controller command to scaffold CRUD operations quickly. Customize the generated controller later.Twig Extensions:
{{ extjs_model() }} to dynamically load models in templates, reducing manual JavaScript includes.Version Control:
web/extjs/generateModel.js) from version control. Use a build step to regenerate them.Testing:
public function testRemoteAction() {
$client = static::createClient();
$client->request('GET', '/
How can I help you explore Laravel packages today?