Please check out our new awesome rad-components!
knplabs / knpradbundle Goto Github PK
View Code? Open in Web Editor NEWRapid Application Development for Symfony2 [UNMAINTAINED]
License: MIT License
Rapid Application Development for Symfony2 [UNMAINTAINED]
License: MIT License
Please check out our new awesome rad-components!
example
console rad:generate:controller Level1/Level2/Level3:index
expected controller namespace
${AppBundleNS}\Level1\Level2\Level3;
generated controller namespace
${AppBundleNS}\Level1\Level2/Level3;
causes: "Parse error: syntax error, unexpected '/', expecting T_NS_SEPARATOR or ';' or '{' in...."
Solution
Replacement for GenerateControllerCommand:execute in L44
$subns = str_replace('/', '\\', dirname(str_replace('\\', '/', $class)));
For example, to register the JMS Serializer Bundle is required to do something like this:
bundles = array(
// ...
new JMS\SerializerBundle\JMSSerializerBundle($this),
// ...
);
In these cases, how to register bundles in kernel.yml ?
Thanks.
I am trying to break my controllers up into two folders, "frontend" and "admin". So I added the following routes to my routing.yml
App:Frontend:Home:index: /
App:Admin:Post:index: /admin/posts/
When I visit the home page of the site I get the following error:
Unable to find controller "App:Frontend" - class "App\Controller\FrontendController" does not exist.
Is this something that should or will be supported by the KnpRadBundle?
Hi
Is there any possibility to find/make this functionality https://github.com/KnpLabs/KnpRadBundle/wiki/csrf-protected-links as external bundle or sth? I got big project and i can't afford to convert it all to KnpRadBundle (sadly i found it too late :() and i'm looking for csrf protection for links. Your solution is the best, but still - it's attached to Rad Bundle. Can anybody help me with that?
I'm using knp translatable behavior and when object is created, translatable fields are persisted normally, but when object is updated changes on translatable fields are ignored. Ex I have this code in updateAction:
...
/*This controller extends RadController*/
if ($form->isValid()) {
$entity->translate('fr')->setName('Chaussures');
$entity->translate('en')->setName('Shoes');
$this->persist($entity, true);
return $this->redirectToRoute('somewhere');
}
...
If instead call RadController shortcuts methods I persist entity like this, works perfect.
$this->getDoctrine()->getManager()->persist($entity);
$this->getDoctrine()->getManager()->flush();
And we should be able to decalre them through configuration maybe. For the moment, it's too error prone.
There doesn't seem to be any mention of licensing in the repository or anywhere I could find. Having something would be reassuring since public domain can sometimes be a bit... sticky.
It's a fact: it's quite hard to get started with the rad edition cause the documention is not good enough.
Let's discuss a plan for a brand new documentation that compiles in RST so we can generate some website/pdf using a shinny theme.
So bellow is a starting draft:
I have a Voter located at App->Security->JobVoter.php
that looks something like this
namespace App\Security;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\Entity\Job;
class JobVoter implements VoterInterface, ContainerAwareInterface
{
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public function supportsAttribute($attribute)
{
return in_array($attribute, [
'OWNER'
]);
}
public function supportsClass($object)
{
return $object instanceof Job;
}
public function vote(TokenInterface $token, $object, array $attributes)
{
if (null === $object || !$this->supportsClass($object)) {
return VoterInterface::ACCESS_ABSTAIN;
}
foreach ($attributes as $attribute) {
if ($this->supportsAttribute($attribute)) {
switch ($attribute) {
case 'OWNER':
if ($token->getUser() !== $object->getCreatedBy()) {
return self::ACCESS_DENIED;
}
break;
}
}
}
return self::ACCESS_GRANTED;
}
}
This is giving me the following error:
FatalErrorException: Error: Cannot use object of type Symfony\Component\DependencyInjection\Reference as array in ../vendor/knplabs/rad-bundle/Knp/RadBundle/DependencyInjection/DefinitionManipulator.php line 12
I like to keep my Controllers namespaced depending on their purpose. For example:
Is this currently possible in KnpRadBundle if not would a pull request be in scope of the project.
Last tag (v2.2) is a month and a half old. Let's make another one to add this 27 new awesome commits! v2.2...develop
ping @Herzult @docteurklein
Installing this great new bundle on Mac Lion with MAMP, getting this error when trying to view a page:
"ErrorException: Catchable Fatal Error: Object of class __PHP_Incomplete_Class could not be converted to string in /Applications/MAMP/htdocs/{PROJECT}/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php line 70"
I can probably solve it with a php.ini setting change, but since I'm using a very common dev environment I wanted to post the issue. Thanks!
What about providing a javascript loaded in the rad base template that will handle DELETE, PUT, PATCH, ... method that can't be handled in html5 directly?
Something like :
jQuery('body').on('click', 'a.delete', function (event) {
event.preventDefault();
if (confirm(jQuery(event.target).data('confirm') || 'Are you sure?')) {
var form = document.createElement('form');
var input = document.createElement('input');
form.method = 'POST';
form.action = event.currentTarget.href;
input.type = 'hidden';
input.name = '_method';
input.value = 'DELETE';
form.appendChild(input);
document.body.appendChild(form);
form.submit();
}
});
I'm getting tired of copy/pasting it to every project I work on ๐
Your skeleton for the Imagine config uses an old bundle (a fork of the first bundle created by @avalanche123 and deleted long ago). This bundle is incompatible with both Symfony (it is written for PR10 or something like that) and Imagine
you should use https://github.com/avalanche123/AvalancheImagineBundle (official basic integration) or https://github.com/liip/LiipImagineBundle (most advanced features as @avalanche123 wanted to keep his own bundle very simple). And the best solution would be to provide the skeleton for both of course :)
Hi guys,
when trying to generate a bundle
"php app/console generate:bundle --namespace=MyNS\MyBundle --format=xml"
I get the following error:
Command "generate:bundle" is not defined.
Is that command supported in KnpRadBundle?
I can't manage to get Doctrine/ORM works.
First of all, seems that I have no doctrine.yml. I don't know if I should install more bundles, but I've got the SolverProblemsException with composer that a lot of people get.
So, is Doctrine currently implemented in RadBundle or should I install it ? If so, what's the way to do it, because I found nothing on it.
If an extends template is missing, it will trigger the missing view handling, which then suggests to create the action template again instead of realizing that its not the action template that is missing, but one of the extends, ie. parent, templates that is missing.
Following example on "csrf protected links", the function link_attr
is not found.
<a {{ link_attr('delete', 'Are you really sure ?') }} href="{{ path('app_member_delete', { 'id': member.id }) }}">Supprimer</a>
I'm using Symfony v2.2.1 and the "develop" branch of this bundle.
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.2.*",
"symfony/swiftmailer-bundle": "2.2.*",
"symfony/monolog-bundle": "2.2.*",
"doctrine/orm": "~2.3",
"doctrine/doctrine-bundle": "1.2.*@alpha",
"sensio/distribution-bundle": "2.2.*",
"knplabs/rad-bundle": "2.3",
"knplabs/knp-menu-bundle":"~1.1.0@dev",
"twig/extensions": "1.0.*@dev",
"symfony/assetic-bundle": "2.1.*",
"kriswallsmith/assetic": "1.1.*@dev",
"doctrine/doctrine-fixtures-bundle": "2.1.*@dev",
"doctrine/data-fixtures": "1.0.*@dev",
"mopa/bootstrap-bundle": "2.1.*@dev",
"mopa/composer-bridge": "*@dev",
"stof/doctrine-extensions-bundle": "~1.1@dev",
"friendsofsymfony/user-bundle": "*",
"sonata-project/admin-bundle": "2.2.*@dev",
"sonata-project/doctrine-orm-admin-bundle": "2.2.*@dev",
"sonata-project/user-bundle": "2.2.*@dev",
"sonata-project/block-bundle": "2.2.*@dev"
},
I set custom project name (not KnpRad) and path in phpunit.xml is wrong
https://github.com/KnpLabs/KnpRadBundle/blob/master/Resources/skeleton/project/phpunit.xml.dist#L18
$ phpunit PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Knp Rad intro suite.php" nor "Knp Rad intro suite.php" could be opened.' in /usr/share/php/PHPUnit/Util/Skeleton/Test.php:100 Stack trace: #0 /usr/share/php/PHPUnit/TextUI/Command.php(152): PHPUnit_Util_Skeleton_Test->__construct('Knp Rad intro s...', '') #1 /usr/share/php/PHPUnit/TextUI/Command.php(125): PHPUnit_TextUI_Command->run(Array, true) #2 /usr/bin/phpunit(46): PHPUnit_TextUI_Command::main() #3 {main} thrown in /usr/share/php/PHPUnit/Util/Skeleton/Test.php on line 100
I didn't use it, but wanted to try it now. And was surprised that it was removed in 2.0. What are the reasons behind that?
I'm trying to follow the installation instructions but it does not install, it only shows question marks.
Lion 10.7.3
PHP (built in) and the Liip one (http://php-osx.liip.ch/)
$ php composer.phar install
?? ???
I wasted my time and crashed my head against the wall today.
I was trying to translate my app by putting translations into src/MyApplication/Resources/translations/messages.fr.yml.
But I still had Shakespeare's language instead of Moliere until I moved translation files into /app/Resources/translations.
What's wrong ? Have you got the same issue ? Looks like a bug for me or maybe we should update the documentation.
Using composition instead of inheritance would be less intrusive by allowing to nest as many composed parser as needed.
the way to overwrite it can be seen here: https://github.com/BeSimple/BeSimpleI18nRoutingBundle/pull/6/files#diff-1 My refactoring is under MIT so you can use the compiler pass to adapt it to your need without any issue.
This will work at best if other bundles wanting to overwrite it also uses composition this way (and not a crappy way forcing to compose the FrameworkBundle service only) but it can work too with bundles using a dumb composition or using inheritance if you take care to apply KnpRadBundle after them (as KnpRad would then take care to do things cleanly)
I wanted to test this promising bundle, bunt during composer install, I get... ;(
[ErrorException]
symlink(): Operation not supported
For the moment it's only possible either via compiler pass or config.yml (right ?)
I'm thinking of an ultimate extension point that would be loaded after all the others.
using TypeGuesser.
We already have a DataTypeGuesser, that knows to add a collection type when the property is type array or Collection.
Same for DateTime.
What could be cool is to add a typeGuesser that knows which type class to use when available (for collection f.e).
Example:
Hi all,
First of all, thanks for this great work. ๐
I've tested routing, forms and datatables and it's really easy to use.
With symfony 2.2 I've been obliged to use this :
class App extends Bundle
{
public function boot()
{
Request::enableHttpMethodParameterOverride();
}
}
Concerning the globale documentation, it is really poor.
For example, reading the code, I found how to add button in the table building this var :
public function indexAction()
{
$items = $this->getRepository('App:User')->findAll();
$routes = array(
'show' => array(
'path' => 'app_user_show',
'label' => 'Show',
'parameters' => array('id' => 'id')
),
'edit' => array(
'path' => 'app_user_edit',
'label' => 'Edit',
'parameters' => array('id' => 'id')
),
'delete' => array(
'path' => 'app_user_delete',
'label' => 'Delete',
'parameters' => array('id' => 'id')
),
);
return array('items' => $items, 'routes' => $routes);
}
and setting it in the twig template like that :
<table class="table table-hover table-bordered table-condensed">
{{ bootstrap_datatable(items, {bootstrap: 'Twitter_Bootstrap', routes: routes}) }}
</table>
But I haven't been able to find such documentation about it.
Thanks for your feedback.
Is there a way to remove all resource routes? I thought something like this might work.
App:Test:
collections:
index: ~
custom:
pattern: /custom/
resources: ~
But I am still getting the following routes when running router:debug
I also tried resources: []
and resources: {}
, which produced the same results
app_test_show GET /test/{id}
app_test_edit GET /test/{id}/edit
app_test_update PUT /test/{id}
app_test_delete DELETE /test/{id}
Even application specific code can become too varied to comfortably sit together in a single bundle.
Please consider allowing multiple bundles according to application needs.
Otherwise you may be limiting this great bundle's applicability to small projects only.
RadBundle seems to basically work with SF2.1.
Therefore it would be nice to have a modified branch and maybe even packagist package for it.
TODOs:
Hi,
I have problem with validation.
In my controller:
$User = new User();
$User->setFirstName('Martin');
$User->setLastName('Grochulski');
$validator = $this->container->get('validator');
$errors = $validator->validate($User);
var_dump($errors);
I have create the validation with annotation in my User Entity,
When I do that, symfony return:
FatalErrorException: Error: Cannot instantiate abstract class Knp\RadBundle\Doctrine\EntityRepository in /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 689
Hi,
when I run this command:
composer.phar create-project -s dev --prefer-dist --dev knplabs/rad-edition my_project
from the http://rad.knplabs.com/#installation
it shows the error from attachment
I'm using Bootstrap with my project, and decided to clone it and use the LESS version.
So, I added the dependency to my composer.json (I had to define a new repository since Bootstrap isn't available natively through Composer), and modified my knp_rad.yml as follows:
all:
# ...
assetic_pipeline:
enabled: true
paths:
- %kernel.project_dir%/Resources/public
- %kernel.project_root%/assets
- %kernel.project_root%/vendor/twitter/bootstrap
# ...
Then, I created a new style.css that contained the following:
/*
*= require libs/boilerplate
*= require bootstrap
*/
But I get an error because Assetic Pipeline looks for the dependency in vendor/twitter/bootstrap/css/, while it should look under vendor/twitter/bootstrap/less.
It'd be nice if I could define additional sub-directories to look in when resolving dependency, e.g..:
all:
# ...
assetic_pipeline:
# ...
types:
css: ["css", "less", "sass", "scss"]
js: ["js", "coffee"]
# ...
What do you think?
I have noticed that actually the RadBundle does not permit to define a correct config TreeBuilder. It would be interesting to give this kind of functionality. Maybe simplify it a little bit.
I am thinking about how to improve the actual AppBundle and add two methods like :
public function buildTree(NodeParentInterface $rootNode);
public function buildContainer(array $config, ContainerBuilder $container)
The buildContainer
method corespond to the standard load
method of an bundle Extension object. Except that the given $config
in this new method is already parsed.
What did you think about this idea ?
like:
- is owner
- is owned
- is myself
Hi,
In my app I want to use the user IP.
I use:
$this->container->get('request')->getClientIp()
And get server public IP
I'm on
dev-develop@dev
Dear @Herzult,
I hope everything is going well for you in the country of Andouillette.
Would it be possible that you add some usage documentation on the flashes tag?
At least, so we can update the base tb layout that still uses app.session.flashes (which is baaaad).
Sincerly yours,
GildasQ.
Hi guys.
In one of my projects I used a quite different division of the repository to which I used to do. The idea was to define the various states of my entity and then chaining these states in the repository to have a code clearer and extensible. I give you a exemble.
This is a simple entity.
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Entity\ProductRepository")
*/
class Product
{
const STATUS_APPROVED = 1;
const STATUS_REJECTED = 0;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $name;
/**
* @ORM\Column(type="string")
*/
protected $createdBy;
/**
* @ORM\Column(type="datetime")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime")
*/
protected $removedAt;
/**
* @ORM\Column(type="integer")
*/
protected $status;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getCreatedBy()
{
return $this->createdBy;
}
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
public function getRemovedAt()
{
return $this->removedAt;
}
public function setRemovedAt($removedAt)
{
$this->removedAt = $removedAt;
return $this;
}
public function getStatus()
{
return $this->removedAt;
}
public function setStatus($status)
{
$this->status = $status;
return $this;
}
}
Now, I want to add a method to her repository to recieved all displayable entites.
My customer told me that a displayable product should be active (should be created and shouldn't be removed) and must have an approved status. So I create this method :
<?php
namespace App\Entity;
use Knp\RadBundle\Doctrine\EntityRepository;
class ProductRepository extends EntityRepository
{
public function findDisplayable()
{
return $this
->build()
->andWhere('p.createdAt <= :today')
->andWhere('p.removedAt > :today')
->andWhere('p.status = :status_approved')
->setParameter('status_approved', Product::STATUS_APPROVED)
->setParameter('today', new \DateTime)
->getQuery()
->getResult()
;
}
}
But, I think is not clear anougth. If the entity grows and the application becomes more and more complex, this repository classe will has a lot of lines and will be unreadable.
My approche is to say : "One method, one state". For exemple, if I extract all states of my customer needs, I've got those states :
If you look at the GeekWeek12 repo, I've splitted my query building in separated methods but it's not clear anougth.
I propose to include custom query builder linked to the customs repository which containes states methods. For our example, it should be a class like this :
<?php
namespace App\Entity;
use Knp\RadBundle\Doctrine\QueryBuilder as BaseQueryBuilder;
use App\Entity\Product;
class ProductQueryBuilder extends BaseQueryBuilder
{
public function whichAreCreated()
{
return $this
->andWhere(sprintf('%s.createdAt <= :today', $this->getAlias()))
->setParameter('today', new \DateTime)
;
}
public function whichAreNotCreated()
{
return $this
->andWhere(sprintf('%s.createdAt > :today', $this->getAlias()))
->setParameter('today', new \DateTime)
;
}
public function whichAreRemoved()
{
return $this
->andWhere(sprintf('%s.removedAt <= :today', $this->getAlias()))
->setParameter('today', new \DateTime)
;
}
public function whichAreNotRemoved()
{
return $this
->andWhere(sprintf('%s.removedAt > :today', $this->getAlias()))
->setParameter('today', new \DateTime)
;
}
public function whichAreApproved()
{
return $this
->andWhere(sprintf('%s.status = :status_approved', $this->getAlias()))
->setParameter('status_approved', Product::STATUS_APPROVED)
;
}
public function whichAreRejected()
{
return $this
->andWhere(sprintf('%s.status = :status_approved', $this->getAlias()))
->setParameter('status_approved', Product::STATUS_REJECTED)
;
}
public function whichAreDisplayable()
{
return $this
->whichAreCreated()
->whichAreNotRemoved()
->whichAreApproved()
;
}
}
It's longer but it's clear and if the customer wants to redifined one of those states, you dont have to read all the repository to apply the modification.
What do you think?
maybe when a class is in folder Validator/Constraints
that extends Constraint
class.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.