On Symfony's Friends of Symfony User Bundle, I managed to modify a profile action that allows me to view specific user profiles instead of only seeing my own. I basically took the Group Controller's function, and made some code useable for the User Controller, as the Group Controller allows you to view the group, using the name in the URL; now in the User Controller, where profile/ becomes profile/mrxxiv. I'm trying to keep profile/ as well, but the way I have the function set up, it's almost impossible due to Symfony giving me an error, telling me about the empty value in the function, where I'd need to enter a username in order to find & view the user's data.
This is the error when not entering a username in the URL:
Controller "FOS\UserBundle\Controller\ProfileController::showAction()" requires that you provide a value for the "$username" argument (because there is no default value or because there is a non optional argument after this one).
I don't want to enter a default value, I just want to find a way to pass the parameter when it's empty as when I use only the url profile/, I can view my own profile data on the spot. Plus I can't be specific against all users. Disregard the IF statement by the way.
public function showAction($username) {
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$user = $this->findUserBy('username', $username);
return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user));
}
While I think that there are no "100% good guys" in this world (no country is), I do think that there are "less bad guys" or "preferred bad guys". From my personal POV, of course, I'd say that I prefer to side with Israel, the US and the Western world before siding with Iran, Hezbollah, Hamas, Russia, China and North Korea.
The "Western world" team has always been better regarding economics, freedoms and human rights than the "non-Western world" team. Israeli people have a degree of prosperity and freedom that Iranian, Russian and North Korean people could only dream about, that's a fact. The same applies to the "Western world" as a whole. Just look at the quality of life of the inhabitants of the "non-Western" world: it's measurably worst by any metric.
So that's why I choose to side with the West, every time. Results speak for themselves. Even if the West isn't perfect and 100% "good", either.
*lose
Anyway, had a feeling this was going to happen eventually which is why I started using NextDNS. The ad blocking on that is amazing (especially on android). It will be interesting to see how it works paired with ublock origin lite as I know the regular ublock origin extension removes a lot of ad placeholders
Question
Mr.XXIV
On Symfony's Friends of Symfony User Bundle, I managed to modify a profile action that allows me to view specific user profiles instead of only seeing my own. I basically took the Group Controller's function, and made some code useable for the User Controller, as the Group Controller allows you to view the group, using the name in the URL; now in the User Controller, where profile/ becomes profile/mrxxiv. I'm trying to keep profile/ as well, but the way I have the function set up, it's almost impossible due to Symfony giving me an error, telling me about the empty value in the function, where I'd need to enter a username in order to find & view the user's data.
This is the error when not entering a username in the URL:
Controller "FOS\UserBundle\Controller\ProfileController::showAction()" requires that you provide a value for the "$username" argument (because there is no default value or because there is a non optional argument after this one).
I don't want to enter a default value, I just want to find a way to pass the parameter when it's empty as when I use only the url profile/, I can view my own profile data on the spot. Plus I can't be specific against all users. Disregard the IF statement by the way.
public function showAction($username) { $user = $this->container->get('security.context')->getToken()->getUser(); if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException('This user does not have access to this section.'); } $user = $this->findUserBy('username', $username); return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user)); }Link to comment
https://www.neowin.net/forum/topic/1128966-php-function-pass-empty-username-value/Share on other sites
14 answers to this question
Recommended Posts