Reputation: 450
Morning guys,
I have two database that are linked, the tables are User
and Theme
, have in mind im not that familliar with php and symfony framework.
a Theme is linked to a User :
/src/Entity/Theme.php
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="published")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
I'm trying to setup a function that would display all the Theme written by this User based of his lastname, from what i understood @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="published")
makes sure my theme isnt only linked by the user_id
but the user entity.
In my ThemeController.php
my function is set up this way :
/**
* @Route("/theme/show/{lastname}", name="theme_created_by")
* 0@param User $ThemeByUser
*/
public function userThemes(User $ThemeByUser){
$html = $this->twig->render('theme/index.html.twig', [
'themes' => $this->themeRepository->findBy(
['User' => $ThemeByUser], ['created_at' => 'DESC']),
]);
return new Response($html);
}
It seems like the query made by Doctrine isn't going thru i get this error :
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.user_id AS user_id_5 FROM theme t0 WHERE t0.id = ?' with params ["Roland"]:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type integer: "Roland"
Which mean Doctrine is expecting a int as a parameter but it is receiving a string. While reading the documentation it seems like the parameters are converted to match anything in the data. Maybe im dont fully understand how it works, just need a little guidance. thank you
Upvotes: 1
Views: 7408
Reputation: 450
Dont know how and why but in my twig file that rendering the function :
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="text-gray-dark">Autheur : </strong>
<a href="{{ path('theme_created_by', {'lastname': theme.user.lastname}) }}">
{{ theme.user.lastname }}
</a>
<br/>
<a href="{{ path( 'theme_show', {'id' : theme.id} ) }}">
<strong>{{ theme.name }}</strong><br/>
</a>
i replace that path line with :
<a href="{{ path('theme_created_by', {'username': theme.user.username}) }}">
{{ theme.user.lastname }}
</a>
changed the paramaters passed in my route too : with username
@Route("/themes/by/{username}", name="theme_created_by")
now it works..
Upvotes: 1