Closed ducho closed 6 years ago
Hello @ducho,
with frontend you mean on the website so not a route under /admin?
Is the route registered correctly in the website kernel (app/config/website/routing.yml) and does the debug command list your new routes: bin/websiteconsole debug:router
. When yes what does bin/websiteconsole debug:router get_spalneo
return
@alexander-schranz
Thanks for quick reply. Yes I mean on the website not under admin.
I need to add custom controller for rest api on frontend.
I tried bin/websiteconsole debug:router with same result:
get_spalneo GET ANY ANY /api/spalneo.{_format}
but... route still not working when i call 127.0.0.1:8000/api/spalneo
@ducho what does bin/websiteconsole debug:router get_spalneo
return? for me it looks the _format is required. does: http://127.0.0.1:8000/api/spalneo.json work?
@alexander-schranz ok i missed .json, but response is
{"error":{"code":404,"message":"Not Found"}}
bin/websiteconsole debug:router get_spalneo
return
Property | Value | ||
---|---|---|---|
Route Name | get_spalneo | ||
Path | /api/spalneo.{_format} | ||
Path Regex | #^/api/spalneo(?:.(?P<_format>json | csv | html))?$#s |
Host | ANY | ||
Host Regex | |||
Scheme | ANY | ||
Method | GET | ||
Requirements | _format: json | csv | html |
Class | Symfony\Component\Routing\Route | ||
Defaults | _controller: ApiBundle:Api:getSpalneo | ||
_format: json | |||
Options | compiler_class: Symfony\Component\Routing\RouteCompiler | ||
Callable | App\ApiBundle\Controller\ApiController::getSpalneoAction |
you can also use bin/websiteconsole router:match /api/spalneo.json --method GET
to see which controller match this rule.
@alexander-schranz the result for bin/websiteconsole router:match /api/spalneo.json --method GET
is same as my previous comment but will never get into this function.
Callable: App\ApiBundle\Controller\ApiController::getSpalneoAction
Is not required to register new route for frontend for Sulu? I think Sulu filters routes because result is still 404.
{"error":{"code":404,"message":"Not Found"}}
@ducho no static routes are prioritized and as the router:match works I think your problem must be in your controller or a custom request listener in the core there also some static routes which work without problems (media download, search). You need to debug. But maybe you have a problem with your webserver configuration so check if the other static routes are working correctly.
@alexander-schranz so when I set SYMFONY_ENV = 'dev'
it works, but not under prod. Should I run something like bin/websiteconsole sulu:build prod
?
@ducho you can pass the environment with -e prod
@ducho did you clear the production cache? as @wachterjohannes mentioned you can add the environment to a command but you dont need to run sulu:build again. can you check bin/websiteconsole router:match /api/spalneo.json --method GET -e prod
@alexander-schranz thank you very much for your help. Now all working correctly. My last question before closing this issue is, if exists channel for consulting because gitter channel nobody using.
@ducho use our slack channel :) you can subscribe to it over the form on the bottom of the homepage http://sulu.io/en#questions
Hi. I have problem with add custom frontend-only bundle. Debug:router return:
get_spalneo GET ANY ANY /api/spalneo.{_format}
but when i make get request, sulu return: The path "/api/spalneo" does not exist.
`namespace App\ApiBundle\Controller;
use FOS\RestBundle\Controller\FOSRestController; use Symfony\Component\HttpFoundation\Response; use FOS\RestBundle\Controller\Annotations as Rest;
class ApiController extends FOSRestController { /**
api_spalneo: resource: "@ApiBundle/Resources/config/routing_api.xml" type: rest prefix: /api
Can anybody help me? Thanks a lot.