Can anyone please help me I'm desperate here !!!
I am working on a symfony 3 project and I have different actions to persist data to database or to update it but none of them is working. The code is fine I'm guessing it's a problem with the routing. This one is the action to add element to database
public function newAction(Request $request)
{
...
if($request->isMethod('POST')) {
...
return $this->redirectToRoute('meeting_new', array(
'meeting' => $meeting
));
...
}
return $this->render('SocialProMeetingBundle::ajoutMeeting.html.twig', array('users'=>$users));
}
and this is the updating action
public function editAction(Request $request, Meeting $meeting)
{
...
if($request->isMethod('POST')) {
...
return $this->redirectToRoute('meeting_edit', array(
'id' => $meeting->getId()
));
}
return $this->render('meeting/edit.html.twig', array(
'meeting' => $meeting,
));
}
and this is my routing file
meeting_index:
path: /
defaults: { _controller: "SocialProMeetingBundle:Meeting:index" }
methods: GET
meeting_show:
path: /show
defaults: { _controller: "SocialProMeetingBundle:Meeting:show" }
methods: [GET, POST]
meeting_new:
path: /new
defaults: { _controller: "SocialProMeetingBundle:Meeting:new" }
methods: [GET, POST]
meeting_edit:
path: /{id}/edit
defaults: { _controller: "SocialProMeetingBundle:Meeting:edit" }
methods: [GET, POST]
meeting_delete:
path: /{id}/delete
defaults: { _controller: "SocialProMeetingBundle:Meeting:delete" }
methods: DELETE
One problem is in your function newAction where you are passing in a meeting parameter and the route doesn't handle it. This code:
return $this->redirectToRoute('meeting_new', array(
'meeting' => $meeting
));
Your route needs to handle the parameter like so:
meeting_new:
path: /new/{meeting}
defaults: { _controller: "SocialProMeetingBundle:Meeting:new" }
methods: [GET, POST]
Related
I have an extbase extension. If I add a new item then I see this error:
PHP Warning: Undefined array key 1 in
/var/www/html/typo3/typo3_src-11.5.13/typo3/sysext/extbase/Classes/Routing/ExtbasePluginEnhancer.php line 202
My method:
public function listAction(): ResponseInterface
{
// List
if ($this->settings['display'] == '0') {
if ($this->settings['categories'] != '') {
if ($this->settings['important'] != '0') {
$articles = $this->getImportantFromCategories();
} else {
$articles = $this->getFromCategories();
}
} else {
if ($this->settings['important'] != '0') {
$articles = $this->getImportantArticles();
} else {
$articles = $this->getArticles();
}
}
}
// Archive
if ($this->settings['display'] == '2') {
$articles = $this->getArchivedArticles();
}
// If not details
if ($this->settings['display'] != '1') {
// Pagination
$articlesArray = $articles->toArray();
$currentPage = $this->request->hasArgument('currentPage') ? $this->request->getArgument('currentPage') : 1;
$paginator = new ArrayPaginator($articlesArray, intval($currentPage), intval($this->settings['perpage']));
$simplePagination = new SimplePagination($paginator);
$articles = $this->articleRepository->findAll();
$this->view->assignMultiple(
[
'articles' => $articles,
'paginator' => $paginator,
'pagination' =>
[
'lastPageNumber' => $simplePagination->getLastPageNumber(),
'firstPageNumber' => $simplePagination->getFirstPageNumber(),
'nextPageNumber' => $simplePagination->getNextPageNumber(),
'previousPageNumber' => $simplePagination->getPreviousPageNumber(),
'startRecordNumber' => $simplePagination->getStartRecordNumber(),
'endRecordNumber' => $simplePagination->getEndRecordNumber(),
'currentPageNumber' => $paginator->getCurrentPageNumber(),
'pages' => $simplePagination->getAllPageNumbers(),
'article_counter' => $this->article_counter,
],
'article_counter' => $this->article_counter,
]
);
}
return $this->htmlResponse();
}
and the getArticles() method:
public function getArticles()
{
$table = 'tx_extension_domain_model_article';
$query = $this->articleRepository->createQuery();
if ($this->settings['sorting'] == 'list') {
$query->statement('SELECT * FROM ' . $table . ' WHERE archived != 1');
} else {
$query->statement('SELECT * FROM ' . $table . ' WHERE archived != 1 ORDER BY crdate DESC');
}
$this->article_counter = $query->count();
return $query->execute();
}
I don't know why this error message is triggered.
The only change is the PHP Version from 7.4 to 8.0.21.
My route enhancer
routeEnhancers:
Plugin:
type: Extbase
extension: Plugin
plugin: News
routes:
- routePath: '/{slug}'
_controller: 'Article::show'
_arguments:
slug: article
- routePath: '/page/{page}'
_controller: 'Article'
_arguments:
page: currentPage
defaultController: 'Article::list'
requirements:
slug: '^[a-zA-Z0-9].*$'
page: '\d+'
aspects:
slug:
type: PersistedAliasMapper
tableName: tx_extension_domain_model_article
routeFieldName: slug
page:
type: StaticRangeMapper
start: '1'
end: '100'
You should look up your extbase plugin route enhancer configuration in your site configuration.
Reading the given error, and look into the corresponding code, it seems that you have a invalid value for a '_controller' or 'defaultController' configuration in there.
It should be something like MyController::myaction .. and taken the error, the second part "::myaction" seems to be missing.
The first error
PHP Warning: Undefined array key 1 in
/var/www/html/typo3/typo3_src-11.5.13/typo3/sysext/extbase/Classes/Routing/ExtbasePluginEnhancer.php line 202
Is solved by adding ::list in the route
- routePath: '/page/{page}'
_controller: 'Article::list'
_arguments:
page: currentPage
This will trigger
PHP Warning: Undefined array key "nonWrappedTag" in /var/www/html/typo3/typo3_src-11.5.14/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 3812
Solved with this TypoScript setup code
lib.parseFunc_teaser < lib.parseFunc_RTE
lib.parseFunc_teaser.nonTypoTagStdWrap.encapsLines >
lib.parseFunc_teaser.nonTypoTagStdWrap.encapsLines {
encapsTagList = p
remapTag.P =
nonWrappedTag =
}
The lines
encapsTagList = p
remapTag.P =
are not important.
I use TYPO3 v10.4.24, events2 v7.1. and the core SEO extension tx_seo.
I configure the sitemap for events2 this way:
plugin.tx_seo {
config {
xmlSitemap {
sitemaps {
events2 {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = tx_events2_domain_model_event
sortField = tstamp
lastModifiedField = tstamp
pid = 2061
recursive = 2
url {
pageId = 917 //PageID Detail Page
fieldToParameterMap {
uid = tx_events2_events[event]
}
additionalGetParameters {
tx_events2_events.controller = Day
tx_events2_events.action = show
}
useCacheHash = 1
}
}
}
}
}
}
}
The sitemap is generated and I can show the detail view. Google accepts the sitemap, too. But the URLs are ugly because the route enhancer is not used. This is my configuration of the route enhancer.
Events2Plugin:
type: Extbase
extension: Events2
plugin: Events
routes:
- { routePath: '', _controller: 'Day::list' }
- { routePath: '/{date}/{event_title}', _controller: 'Day::show', _arguments: { date: 'timestamp', event_title: 'event' }}
- { routePath: '/events/{date}', _controller: 'Day::showByTimestamp', _arguments: { date: 'timestamp' }}
- { routePath: '/{location}', _controller: 'Location::show', _arguments: { location: 'location' }}
- { routePath: '/listpage-{page}', _controller: 'Day::list', _arguments: { page: '#widget_0/currentPage' }}
defaultController: 'Day::list'
defaults:
page: '0'
requirements:
date: '\d+-\d+-\d+_\d+'
event_title: '^[a-zA-Z0-9\-_]+$'
aspects:
date:
type: TimestampMapper
format: Y-m-d_Hi
event_title:
type: PersistedAliasMapper
tableName: tx_events2_domain_model_event
routeFieldName: path_segment
location:
type: PersistedAliasMapper
tableName: tx_events2_domain_model_location
routeFieldName: slug
page:
type: StaticRangeMapper
start: '1'
end: '100'
What can I do that the route enhancer is used as with other extensions.
Your RouteEnhancer configuration for detail view requires a {date}. You only add action and controller to URI in Sitemap configuration.
Please add
tx_events2_events.timestamp = 0
to section „additionalGetParameters“
I'm working in an API rest with Symfony, FOSRestBundle.
i have a route who return some informations about the user, and i don't know why the return is always null in Postman.
/**
* #Route("/api/user/{id}", name="api_user_informations")
* #ParamConverter("user", class="UserBundle:User", options={"id" = "id"})
* #Method("GET")
*/
public function indexAction(Request $request, User $user = null)
{
if (!$user):
return new JsonResponse([
"code" => Response::HTTP_NOT_FOUND,
"error" => "No user found with this id."
]);
endif;
return new JsonResponse($user);
}
What is wrong with this ?
config.yml
fos_rest:
routing_loader:
include_format: false
view:
view_response_listener: true
format_listener:
enabled: true
rules:
- { path: '^/', priorities: ['json'], fallback_format: 'json' }
Thanks boys :)
I am very new to Aurelia and just trying to apply navigation to my project.Though i import aurelia-router still it says RouterConfiguration and Router are undefined in constructor
import {Todo} from './ToDo/todo';
import {RouterConfiguration, Router} from 'aurelia-router';
export class App {
heading = "Todos";
todos: Todo[] = [];
todoDescription = '';
router :any;
list: any[];
constructor(RouterConfiguration: RouterConfiguration, Router: Router) {
this.todos = [];
this.configureRouter(RouterConfiguration, Router);
//console.log("klist", this.list);
}
//config.map() adds route(s) to the router. Although only route, name,
//moduleId, href and nav are shown above there are other properties that can be included in a route.
//The class name for each route is
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.title = 'Aurelia';
config.map([
{ route: '', name: 'home', moduleId: 'home/home', nav: true, title: 'Home' },
{ route: 'users', name: 'users', moduleId: './Friends/Friends', nav: true },
//{ route: 'users/:id/detail', name: 'userDetail', moduleId: 'users/detail' },
//{ route: 'files/*path', name: 'files', moduleId: 'files/index', href: '#files', nav: 0 }
]);
}
addTodo() {
if (this.todoDescription) {
this.todos.push(new Todo(this.todoDescription));
// this.todoDescription = '';
}
}
}
By convention, Aurelia looks in the initial class that loads (App) for the configureRouter() function and executes it. This means, you do not have to inject anything in the constructor.
It looks like you've simply added too much. I think fixing your sample seems to be as easy as removing some stuff, like so:
import { Todo } from './ToDo/todo';
import { RouterConfiguration, Router } from 'aurelia-router';
export class App {
heading = "Todos";
todos: Todo[] = [];
todoDescription = '';
list: any[];
constructor() {
// note: removed routing here entirely (you don't need it)
// also, you've already declared this.todos above, so no need to do it here again
}
configureRouter(config : RouterConfiguration, router : Router): void {
this.router = router;
config.title = 'Aurelia';
config.map([
{ route: '', name: 'home', moduleId: 'home/home', nav: true, title: 'Home' },
{ route: 'users', name: 'users', moduleId: './Friends/Friends', nav: true }
]);
}
addTodo() {
// removed this for brevity
}
}
This should resolve your 'undefined' errors on Router and RouteConfiguration. As an additional note, don't forget to add the <router-view> to your html template as well. Otherwise, you'll get no errors but the views won't show up either:
<template>
<div class="content">
<router-view></router-view>
</div>
</template>
Great documentation on this can be found at the Aurelia Docs - Routing.
here is how I have routing setup.
routes.MapHttpRoute(
name: "Authors",
routeTemplate: "api/authors",
defaults: new { controller = "authors" }
);
controller action method
// GET /api/authors/
public string GetAuthors(string author_ids)
{
return data;
}
Url http://site.com/api/authors?author_ids=1 actually calls controller action but when I don't pass querystring parameter, it says no controller action matching found.
How to handle optional querystring parameter when defining route?
// GET /api/authors/
public IEnumerable<string> GetAuthors()
{
return data;
}
You will need to define an action that takes no parameters.
It would be better, however, to add id to your route as optional:
routes.MapHttpRoute(
name: "Authors",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
You can be specific like:
routes.MapHttpRoute(
name: "Authors",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
and Action can be:
// GET /api/authors/?XXXX
public IEnumerable<string> GetAuthors( [FromUri] String author_ids)
{
return data;
}
This will only match query string . [FromUri] lets the parameter to be taken from query string.
You may specific like:
routes.MapHttpRoute(
name: "Authors",
routeTemplate: "api/{controller}/{author_ids}",
defaults: new { author_ids = RouteParameter.Optional }
);