Hi,
is there a way to register a controller for every page-load. What I want to do is a section named "mostly viewed pages"
So, what I want to build a controller which checks a get parameter like ?search_term=huhu
if the get parameter is present
-get the node id, check the type: does it has a property counter?
I would create a new db table / Domain Model that stores URI (or Identifier) + Count (+ whatever you need) into a separate table. Then you can use a custom FrontendNodeRoutePartHandler that extends the original one (from neos) and update the page count for the requested page. You can also restrict this to only count in the live workspace. Hope this helps.
Hi Benjamin, I did everything you mention but there is a problem by storing data in the database.
When I try to add data manually with XCommandController it works. But unfortunately, the same code (create entity and initialize,create repository and add) doesn’t work when the Repository is called by CustomRoutePartHandler in the function convertRequestPathToNode. Do you have any ideas what is missing?
Wild guess: You (your visitors) are requesting the affected locations via a GET request - which is a safe request - and thus Neos does not start “the part of its persistence that persists changes”. That is by design, as a safe request should not alter any data.
Of course, your case is perfectly valid: such small data alterations, as visitor-counting, logging, etc… might be done even on safe requests. Now I do not really know the Neos / Flow code well, but you could look for a method like PersistenceManager->persistAll() and call that explicitely.
Exclaimer: I don’t know anything, neither your case nor Neos by heart. Just guessing.
I would really avoid that. GET requests are not meant to change the server state and even for these minor things you might run into trouble if you do so.
To name a few caveats:
GET requests are meant to be cacheable – if the browser or a proxy caches the request your view-counter won’t be called
GET requests are allowed to be followed by search engines… do you want to count the google bot?
I would suggest to increase the view counter via an AJAX (POST) request when the page has been loaded.
See [SOLVED] Counter for survey or page views for a related question
The challenge now is to link to the nodes. When I try to link to the node via its identifier I got some error "node:// URI conversion requires a context node to be passed"
Is there any solution for this?