php - 我如何使用与 Doctrine 的关系?
问题描述
我正在一个网站上存储系列。
我的数据库包含一个 Programs 表和一个 Category 表。类别表有一个ID
和一个name
。
Programs 表包含有关该程序的所有信息以及与其关联的类别 ID。
我有一个/category/$categoryName
功能。
我想通过user-specified $categoryName,
显示此类别中的所有程序。
public function category(string $categoryName):Response{
$categoryInfos = $this->getDoctrine()
->getRepository(Category::class)
->findOneByName($categoryName);
$categoryID = $categoryInfos['id'];
给我->
“不能将 App\Entity\Category 类型的对象用作数组”
拥有 后category ID
,我可以显示属于该类别的所有程序,但
1)我无法检索身份证
2)我想知道是否没有更简单的命令来做我想做的事情。
解决方案
/**
* @Route("/category/{categoryName}", name="category")
*/
public function category(string $categoryName): Response
{
$categoryInfos = $this->getDoctrine()
->getRepository(Category::class)
->findOneByName($categoryName);
$categoryInfos->getId();
return $this->render('home.html.twig');
}
嗯,就是这样。
推荐阅读
- mongodb - 初始化时解析服务器错误:“试图确保已经有重复的类的字段唯一性。”
- javascript - KnockoutJS 过滤数组
- java - 当需要 nativeJdbcExtractor 时,Spring 5 JDBC 方法是什么?
- sql - 根据另一个 CTE 百分比从列表中提取最高百分比的 ID
- javascript - url 资源部分的正则表达式
- c# - 验证信息的格式不正确。检查 .net core 中 Azure Ratecard API 中 Authorization 标头的值
- objectbox - ObjectBox 将两列相加
- javascript - 如何从 cookie 中获取价值以输入“日期”?
- r - 验证时间序列索引
- java - 我的 java 程序卡在 Transport.send(message) 行