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));
}
I don't know why someone said useless, but it does have that pesky kernel driver bundled, and it's in perennial turmoil. When it goes bad, it goes very bad, and it's impossible to predict when it will due to system differences. I know that they're in the middle of development for a major new version that will include a completely new driver, one that they expect will largely solve the problem, but that's a ways out and it's unproven at this point.
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