I have a weird issue happening. My app uploads an image then returns an absolute URL eg. http://localhost:8000/uploads/images/12-6.jpg to the path via json through from where the user can crop amongst other edits.
This seems to work fine in production mode but I am having problems in dev because for some reason the app decides to match the route defines below:
category:
path: /{parent}/{id}/{category}
defaults: { _controller: "AppBundle:Default:showCat", category: '' }
Is there anyway I can prevent this from happening?
Thanks in advance
Maybe it is working in production because you didn't clear the cache with env=prod?
Your route is too broad, it match almost everything. uploads/images/12-6.jpg match your route with parent: upload, id : images, category 12-6.jpg.
Take a look at the doc if you need more information
You should add a prefix to your route (like categ/{parent}/{id}/{category}) or use requirements like below:
category:
path: categ/{parent}/{id}/{category}
defaults: { _controller: "AppBundle:Default:showCat", category: '' }
requirements:
id: \d+
I recommend you to use a prefix AND a requirement, to not have future route problems
Related
For a project I am making I will be using a route that looks something like this: collection/id. The server returns an 404 error when the given ID does not exist.
When this happens I would like to push the 404 error page that I have in my router.
{
name: 'notfound',
path: '/:pathMatch(.*)*',
component: () => import('../views/PageNotFoundView.vue'),
}
Now this is achieved by calling the following code: this.$router.push('/notfound');. However, this also changes the URL in the browser which is not something I would want. When reloading the page you should be going to collection/id.
Is there any way to push a navigation route (or component?) without changing the URL displayed?
Example: https://google.com/ajdfkasf doesn't go to https://google.com/404 but rather you keep the link and can refresh it. I could include the component in the view instead of trying to solve this with routes, but that would add overhead to all kinds of views.
I am trying to create a custom admin page in drupal 8 admin
i have create a custom module name custom_admin also I have added the below code in
"custom_admin.routing.xml"
custom_admin.contactformlisting:
path: '/admin/structure/contactformlisting'
defaults:
_content:
'\Drupal\custom_admin\Controller\AdminController::contactformlisting'
_title: 'Contact Form Listing'
requirements:
_permission: 'administer contact forms listing'
_access: 'TRUE'
custom_admin_permissions.yml
administer contact forms listing:
title: 'Administer contact forms listing'
in custom_admin.links,menu.yml
custom_admin.contactformlisting:
title: Contact Form Data Listing
description: 'This is a contact form listing page link`enter code here`'
parent: system.admin_structure
route_name: custom_admin.contactformlisting
But still revceving Page not Found can anybody help me in these
Not sure if it's just a typo above, but the file "custom_admin.routing.xml" should be custom_admin.routing.yml* (yml instead of xml). The permissions yml needs to be module_name.permissions.yml - you have module_name_permissions.yml (underscore instead of period).
I also notice some spacing issues in the routing file for _access:(again not sure if just a typo here), but yml format is very specific. They need to all be indented 2 spaces.
If it's still not working, I would suggest removing the _access property altogether from the routing yml and set _permission: TRUE temporarily, just to remove any other variables that could be interfering.
I'm building a web application using symfony2. I have different types of users with different roles; ROLE_STUDENT and ROLE_TEACHER, those two user can access a course's details; if the user is a teacher, a button edit is shown and if it's the student then a button subscribe will be shown, and actually this is not secure because it just hides the path to the controllers action, if the student types in the address bar /course/2/edit the edit action would be executed so I had to secure the action using #security annotation:
This is what I have done so far:
/**
* #Security("has_role('ROLE_TEACHER')")
*/ public function editAction()
{}
and in twig :
{% if is_granted('ROLE_TEACHER') %}
edit
{% elseif is_granted('ROLE_STUDENT')%}
subscribe
.
The problem is that I have a lot of accessible content to both users and I think there is a better solution to this instead of copy/past the same code all over. I'm new to Symfony 2, please bear with me.
There are multiple ways to achieve this but what you are doing is not wrong.
One way to achieve this is to set ROLE for the ROUTES so that ROLE_STUDENT roles can only access URLs that will be something like this website.com/students and ROLE_TEACHER can only access website.com/teachers
access_control:
- { path: ^/student/, roles: ROLE_STUDENT }
- { path: ^/teamleader/, roles: ROLE_TEACHER }
You can then set the edit route only for teachers like website.com/teachers/course/2/edit this way no edit route is going to be available for ROLE_STUDENT and they will get 404 error or access denied error if they try to access teacher route. You can do the same for the subscribe feature.
Like I said there are more ways to achieve this and this is one of them.
I'm currently toying around with making a framework-only SilverStripe site and so far so good - I've set up a controller and some models and all is well there, however I'm having issue with creating a login system.
It seems the $Form variable that normally displays the login form when you visit /admin doesn't display anything. Should it? I thought that it would, however it is not doing.
I guess my question is - do framework only sites use the default login form, and if so what are the first steps to troubleshoot why the form is not showing on my site? Could it have something to do with routes?
Here is my code:
Routes.yml
---
Name: app
After: 'framework/routes'
---
Director:
rules:
'': 'GanttController'
'$URLSegment//$Action/$ID/$OtherID': 'GanttController'
GanttController.php
<?php
class GanttController extends BaseController {
public function index() {
return $this->customise(new ArrayData(array(
'Title' => 'Gantt Chart'
)))->renderWith(array(
'GanttController',
'Page'
));
}
Page.ss
<html>
<head>
<title>$Title</title>
</head>
<body>
<div class="header">
<h1>Gantt</h1>
</div>
<div class="pane">
$Layout
$Form
</div>
</body>
</html>
If I add the line 'admin': 'AdminRootController' to my YAML routes and go to /admin, instead of it loading up my project it loads up the get started with the SilverStripe framework page, where it links you to the docs on adding controllers/templates.
the framework should display the $Form given that you have a template that uses it.
the framework is still designed to have a frontend, this means to 2 things:
framework will use templates/Page.ss as default template for frontend as usual
if you want the admin / or the secuirty login form, you need to access this controller
you can do this 3 ways:
access it via the already existing route: /admin or /Security/login?backURL=/the/url/to/redirect/to/after/login
use a http redirect make / redirect to /admin
if you don't want a frontend at all, you just use Page.ss for the login template and make / to show the same thing as /admin by assiging the route / to the AdminRootController with the following yml config:
File: mysite/_config/routes.yml
---
Name: mysiteroutes
Before: '*'
After:
- '#rootroutes'
- '#coreroutes'
- '#modelascontrollerroutes'
- '#adminroutes'
---
Director:
rules:
'': 'AdminRootController'
if this does not answer your question and you still can't get the form to display, please paste your code (your route configs, your Page.ss, and any relevant Controller you might have).
My goal is to recognize the local user's browser and automatically set the language.
Then allow the user to change language and keep it on other pages.
At the time I set the routes in this way:
# homepage not localized: load the homepage with default language
index_not_localized:
path: /
defaults: { _controller: "AcmeSiteBundle:Default:index", _locale: %locale% }
acme_site:
resource: "#AcmeSiteBundle/Controller/"
type: annotation
prefix: /{_locale}
defaults: { _locale: %locale% }
requirements:
_locale: %route_locale_requirements%
When the user enters the page example.com without specifying the language in the local route is set by default, and the page there is a switcher that allows you to change the language:
<ul class="dropdown-menu">
{% for locale in ['en', 'it'] %}
<li>
<a href="{{ path('homepage', {'_locale': locale}) }}">
</li>
{% endfor %}
</ul>
How do I do what I want?
I have to create a listener? I have put the local session?
I'm confused, I read several answers but have not found a clear answer!
There are at least two ways, but both of them don't gave you 100% guarantee to detect locale and detect it right.
The first is to use $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable. It's gotten via HTTP Headers and can even doesn't exist.
The second is to use 3rd-side services to detect country by IP address and then compare country name to some local table of countries and their locales. For example:
http://api.hostip.info/get_html.php?ip=127.0.0.1
For more information and comments look at this question: Simplest way to detect client locale in PHP
And the final point is to integrate locale detection into the symfony2 project. This is the simplest part. You just need to use kernel.request event listner. Everything is perfectly explained (with examples) here: Symfony 2.1 set locale