Hello i have a strange problem, while using FostRestBundle.
First error is :
InvalidArgumentException: Every parent controller must have get{SINGULAR}Action($id) method
where {SINGULAR} is a singular form of associated object
And the second one :
Cannot import resource "/home/a15net/public_html/game/src/ATL/ContentBundle/Resources/config/api_routing.yml" from "/home/a15net/public_html/game/app/config/routing.yml".
I'v checked my all "YAML" files but there was no indent problems.
Tried to update composer twice nothing helped.
Edit : Config.yml > http://goo.gl/dqCAu
You have to remove the 'type' from this import statement fro your routing.yml
atl_content_api:
resource: "#ATLContentBundle/Resources/config/api_routing.yml"
Inside the api_routing.yml you can specify the rest type for each controller like,
acme_user_rest:
resource: Acme\UserBundle\Controller\UserRestController
prefix: /api
type: rest
this blog will help you to implement the sme
--- NOT --- SOLUTION :
If a route has a parent route, you must not put "type:rest" to it. You have to use "type:rest" only in parent routes.
Sample :
catalogs:
type: rest
prefix: api
resource: ATL\CatalogBundle\Controller\API\CatalogsController
options:
expose: true
taxonomy:
parent: catalogs
resource: ATL\CatalogBundle\Controller\API\TaxonomyController
options:
expose: true
I will not choose this as correct answer until more comments and other solution suggestions writed.
Edit
When you remove type:rest from children route, it is not a rest route anymore.
Related
I'm trying to figure out with Sylius routing, based on Symfony framework. I found that code
sylius_admin_channel:
resource: |
alias: sylius.channel
section: admin
templates: "#SyliusAdmin\\Crud"
except: ['show']
redirect: update
grid: sylius_admin_channel
permission: true
vars:
all:
subheader: sylius.ui.configure_channels_available_in_your_store
templates:
form: "#SyliusAdmin/Channel/_form.html.twig"
index:
icon: share alternate
type: sylius.resource
But I could not find any information what is it | for resource. Any help?
Thanks.
It's the YAML syntax for a multi-line string (that preserves newlines).
So sylius_admin_channel is a mapping that has two keys (resource and type) whose values are both string types.
It can be confusing to see in this instance because the string happens to also be valid YAML. I edited your question to include syntax highlighting for YAML which makes this a little more obvious, visually.
If I didn't know any better, I would have guessed that the | is there in error and resource should actually have a mapping type for its value. If you remove the |, then same symbols that were within that string still produce valid YAML for the whole file, but the value of resource would be a mapping, rather than a string.
Notice the difference in syntax highlighting, compared to the yaml in the question with the | removed:
sylius_admin_channel:
resource:
alias: sylius.channel
section: admin
templates: "#SyliusAdmin\\Crud"
except: ['show']
redirect: update
grid: sylius_admin_channel
permission: true
vars:
all:
subheader: sylius.ui.configure_channels_available_in_your_store
templates:
form: "#SyliusAdmin/Channel/_form.html.twig"
index:
icon: share alternate
type: sylius.resource
I'm trying to implement OAuth2 in my actual symfony2 project using the FOSOAuthServerBundle.
I've been following this Article to implement it.
Since i don't use FOS User bundle i had to create a UserProvider.
I'm also using A User Repository as he did in his Article.
I've been stuck with this error :
ContextErrorException: Catchable Fatal Error: Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given, called in /app/cache/dev/appDevDebugProjectContainer.php on line 3527 and defined in /app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php line 67
I've followed the given code for services.yml:
And converted it to Yaml, here my file (services.yml) :
imports:
- { resource: parameters.yml }
parameters:
# wca_transition.example.class: WCA\TransitionBundle\Example
collection.import.from_email: "%import_from_email%"
collection.import.to_email: "%import_to_email%"
platform.entity.user.class: WCA\ServerBundle\Entity\Profile
platform.user.provider.class: WCA\ServerBundle\Provider\ProfileProvider
services:
# wca_betosee_transition.example:
# class: %wca_transition.example.class%
# arguments: [#service_id, "plain_value", %parameter%]
collectionImportCommand:
class: WCA\ServerBundle\Command\CollectionImporterCommand
calls:
- [setContainer, ["#service_container"] ]
platform.user.manager:
class: Doctrine\ORM\EntityManager
factory-service: doctrine
factory-method: getManagerForClass
arguments: ["%platform.entity.user.class%"]
platform.user.repository:
class: WCA\ServerBundle\Model\ProfileRepository
factory-service: platform.user.manager
factory-method: getRepository
arguments: ["%platform.entity.user.class%"]
platform.user.provider:
class: "%platform.user.provider.class%"
# arguments: ["#platform.user.repository"]
platform.grant_type.api_key:
class: WCA\ServerBundle\OAuth\ApiKeyGrantExtension
arguments: ["#platform.user.repository"]
tags:
- { name: fos_oauth_server.grant_extension, uri: http://mywebsite.local/grants/api_key }
I suppose the given error is coming from my configuration but i don't see what could be wrong since i followed what was given. Either the services created don't get the given arguments ("none given") or i don't pass the correct ones.
Any ideas or hints?
PS : If you need any other files, don't hesitate to ask, i'll update the post.
I doubt if it will help but try changing factory-service,factory-method to factory_service and factory_method to match the Symfony documentation.
Sounds like it is the only article that describes very well how to implement FOS OAuth2 bundle, even better than their own documentation.
But for some reason, services are defined in xml which I find very weird and ugly.
Anyway, as #Cerad mentioned, if you translate the xml service to the yaml format, then you'll have to replace the - by _ and it will work fine.
I'm trying to build my own CMS based on Symfony 2 since I swapped jobs and now require some symfony practice, but got stuck when trying to do something sensible with routes. In Zend it was possible with preDispatch so I hope Symfony 2 will have something similar too.
Consider this URL: http://www.example.com/page_one/sub_page/another_sub_page/yet_another_sub/
What I am trying to achieve is to have http://www.example.com/page_one/ matching to some controller and getting me the content of the page that has the url_string parameter same as that portion of URL. Then http://www.example.com/page_one/sub_page/ should also match to the same controller but render content for the sub_page portion of URL.
The route must match n portions because I cannot know how deep the structure might go.
So I will not accept something like
/{slug1} or
/{slug1}/{slug2} or
/{slug1}/{slug2}/{slug3}
as that is nonsense.
I am planning to make this route as last one in the routing config so should there be some matches on other routes they will be picked up instead, and this one despite it is most important route will be last resort matching kinda thing.
Using the following config will match all urls, and the entire path will be passed into the controller "slug1/slug2/slug3".
SymfonyBundle/DefaultBundle/Resources/config/routing.yml:
symfony_default_page:
path: /{path}
defaults: { _controller: SymfonyBundle:Default:page }
requirements:
path: "^.+"
Or** ou can also use regex in the requirements path. This will exclude "admin", "login", "blog", however it's much easier if you simplify things and just place the routing in the correct order like you said
requirements:
path: "^(?!admin|login|blog).+"
app/config/routing.yml
By importing the default bundle routing last, it means any routing yml files above will take priority and therefore not match the default route which will catch any url.
SymfonyAdminBundle:
resource: "#SymfonyAdminBundle/Resources/config/routing.yml"
prefix: /admin
#import this last
SymfonyDefaultBundle:
resource: "#SymfonyDefaultBundle/Resources/config/routing.yml"
prefix: /
Controller:
class DefaultController extends Controller
{
public function pageAction($path)
{
//You could split the URL and handle accordingly, also filter / escape?
$parts = explode("/", $path);
}
}
When setting up SonataAdmin, you have to add an entry like this one:
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
In this entry, what does resource: . do? It's somewhat unusual syntax and I'd like to add a footnote about it to the SonataAdmin docs.
The routing component needs a resource attribute (at least with sf2.0). The AdminPoolLoader class is in charge on loading the route and the support method only check the type attribute and not the resource name provided ....
So the dot is just a value that others RoutingLoader cannot validate and generate errors...
I'm getting the following errors when I try to run phpunit on my symfony project:
$ phpunit -c app
1) [...]\DefaultControllerTest::testIndex
Symfony\Component\Config\Exception\FileLoaderLoadException: Cannot import resource "/srv/http/typeform/app/config/config.yml" from "/srv/http/typeform/app/config/config_dev.yml".
/srv/http/typeform/vendor/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:89
[...]
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11
Caused by
Symfony\Component\Yaml\Exception\ParseException: You cannot define a mapping item when in a sequence in "\/srv\/http\/typeform\/app\/config\/config.yml"
/usr/share/pear/Symfony/Component/Yaml/Parser.php:116
[...]
/srv/http/typeform/app/bootstrap.php.cache:520
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11
It seems that it crash when I call static::createClient();
Here's my config_test.yml
imports:
- { resource: config_dev.yml }
The errors you are getting suggest that the app is failing to parse your 'config.yml' because "You cannot define a mapping item when in a sequence".
This means that in a yml file when defining array values you cannot provide both mapping entries in the form "key: value" and sequence entries in the form "- item" - all values must be either one or the other form.
So, this is ok:
group:
key: value
key: value
This is also ok:
group:
- item
- item
This is not ok:
group:
key: value
- item
The errors suggest that there is an occurrence of the last form in your config.yml, although if this is the case it ought to cause problems running your app in the browser and not just under phpunit.
Additionally, to redbirdo's answer, you should be aware that you might need to use - under the required tag's items. For example:
UserLogin:
type: "object"
required:
- email
- password
security:
basicAuth: [] .......