EddieF, on 04 January 2013 - 02:44, said:
Are you using this function to get the profile then?? If so, return out of the function if you aren't using it:
Edit:
If thats throwing the exception, skip it like posted a couple posts above?
n_K, on 04 January 2013 - 02:45, said:
So you want it to get the profile of the logged in user when no profile is given?
if (is_null($Username))
{
GLOBAL $x;
$Username = $x;
}
$x being the variable that holds the logged in username, if it's a session variable you can remove the GLOBAL line.
The function "findUserBy" is the function that searches for the user, it's right under the showAction function. There's already if(empty) exception there, but even if I modify it. I can't get the logged in user info as another exception from the showAction will appear, thus into a paradox (ahh hell).
EDIT:
Let me try, using 2 different functions, since this is a controller working with a router. I'll try to render profile/ and profile/{user} from 2 different public functions.
EDIT #2:
Really appreciate your help guys. I used 2 different functions as said by also using the router to modify what function I want to use.
XML Router:
<route id="fos_user_profile_show" pattern="/">
<default key="_controller">FOSUserBundle:Profile:main</default>
<requirement key="_method">GET</requirement>
</route>
<route id="fos_other_user_profile_show" pattern="/{username}">
<default key="_controller">FOSUserBundle:Profile:show</default>
<requirement key="_method">GET</requirement>
</route>
Controller:
/**
* Show the main user
*/
public function mainAction()
{
$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.');
}
return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user));
}
/**
* Show the user
*/
public function showAction($username)
{
$user = $this->container->get('security.context')->getToken()->getUser();
$user = $this->findUserBy('username', $username);
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user));
}
Edited by Mr.XXIV, 04 January 2013 - 03:07.