Doctrine orm 什么';使用zf2和doctrine2的permalink数据库的最佳方法是什么?

Doctrine orm 什么';使用zf2和doctrine2的permalink数据库的最佳方法是什么?,doctrine-orm,zend-framework2,permalinks,Doctrine Orm,Zend Framework2,Permalinks,我正在用zf2和条令建立一个网站。如何将永久链接保存到我的数据库?最好的方法是什么?我应该在实体中保存永久链接吗 //Product Doctirine Entity public function setProdName($prodName){ $this->prodName = $prodName; //is this right way? $this->setSeoLink = urlhelper->url($prodName); }

我正在用zf2和条令建立一个网站。如何将永久链接保存到我的数据库?最好的方法是什么?我应该在实体中保存永久链接吗

//Product Doctirine Entity

public function setProdName($prodName){
     $this->prodName = $prodName;

     //is this right way?
     $this->setSeoLink = urlhelper->url($prodName);
}

我建议您使用散列创建URL,如

/this-is-the-product-title-xyz123.html
其中xyz123是产品的散列

这样做你会有这些优势

1) 你可以随时更改你的产品名称,你的产品总是可以访问,即使搜索引擎或其他网站的链接有旧的,例如两者都有

/this-is-my-product-xyz123.html 

会有用的

2) 你没有向人们展示真实的身份

为此,我使用模块创建了一个返回已配置对象的factory服务,然后您可以使用以下代码加密/描述:

$hashids = $this->getServiceLocator()->get('my.service.hashid');
// decrypt having hash
$id = $hashids->decrypt($hash);
// encrypt having id
$hash = $hashids->encrypt($id);
html后缀就是一个例子,您可以根据需要创建url

$hashids = $this->getServiceLocator()->get('my.service.hashid');
// decrypt having hash
$id = $hashids->decrypt($hash);
// encrypt having id
$hash = $hashids->encrypt($id);