问题描述
我有实体联系人
<?PHP
namespace App\Entity;
use App\Repository\ContactRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ContactRepository::class)
*/
class Contact
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string",length=50)
*/
private $firstName;
/**
* @ORM\Column(type="string",length=50)
*/
private $lastName;
/**
* @ORM\Column(type="date",nullable=true)
*/
private $dob;
/**
* @ORM\Column(type="string",length=50)
*/
private $email;
/**
* @ORM\Column(type="string",length=15)
*/
private $phone;
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getdob(): ?\DateTimeInterface
{
return $this->dob;
}
public function setdob(?\DateTimeInterface $dob): self
{
$this->dob = $dob;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
}
我想使用以下URL选择一个(或多个)联系人:/c00210/readallbyparam/{routeProperty}/{routeValue}
例如:/c00210/readallbyparam/lastname/Mendelsohn
这应该返回2条记录:
- Felix Mendelsohn
- 范妮·门德尔松
如何编写render()函数? 如何编写树枝指令?
我想我应该使用元数据,但是我不知道
++++++++++++++++++++++++++++++++++++++++
这是我控制器中的功能
/**
* @Route("/c00210/readallbyparam/{routeProperty}/{routeValue}",name="c00210_read_all_by_param")
*/
public function findAllByparam( $routeProperty,$routeValue)
{
$property = $routeProperty;
$value = $routeValue;
$repository = $this->getDoctrine()->getRepository(Contact::class);
$contacts = $repository->findAll();
return $this->render('c00210/readbycriteria2.html.twig',[
'function' => 'find(<id>)','description' => 'finds the with the given Id','property' => $property,'value' => $value,'contacts' => $contacts,]);
routeProperty应该是列名,而routeValue应该是列值
应该等同于
SELECT * FROM contacts WHERE lastname = 'Mendelsohn'
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)