2

I'm working on a project with Zend Framework

Users will be able to post announcement on the website.

For now you can consult them with an URL formatted like (for the announcement with id = 60)

mysite.com/announcement/view/id/60

The result I want, for a better SEO, would be under the form of

mysite.com/announcement/[CITY NAME]/[ZIPCODE]/[TYPE OF GOOD]/[STREET NAME]-[ID]

all of [VARIABLE] are stored in a database and easily accessible.

However, I came up with solutions poorly efficient so I'd like to know the different ways to make the URL rewriting, and the most efficient ones.

For now, I thought about generating the URL the "hard" way when the users post their announcement in a database, and create new routes in my Bootstrap.php when the user connect. This seems ok but I think that it could take a really long time when the volume of announcement will be big.

The second solution I thought of was to generate directly the URL in a file, like an .xml file, that I could load when the user connects too, but that will pose the same problem.

Is there a way to create theses routes efficiently ?

The solution of the RewriteEngine of Apache doesn't seem to be quite flexible for that kind of wanted behaviour ...

For information, the volume of announcement will most likely be over 10 000, so the problem of efficiency is quite big.

4

2 回答 2

2

使用 zend 框架,您不必分配每个端点,因为它只是布局

$route = new Zend_Controller_Router_Route(
            'announcement/:city_name/:zipcode/:type_of_good/:street_name/:id',
            array("controller"=>"accouncement", "action"=>"view-details"));

在控制器中,那么您可以将它们用作

$this->_request->getParam("zipcode");
于 2013-06-04T21:30:30.650 回答
2

最好的解决方案是使用Zend_Controller_Router_Route_Regex

例子

$route = new Zend_Controller_Router_Route_Regex(
 'announcement/(.*?)/(.*?)/(.*?)/(.*?)\-([0-9]*)',
  array(
    'announcement' => 'archive',
    'action' => 'view'
  ),
  array(
    1 => 'city_name',
    2 => 'zipcode',
    3 => 'type_of_good',
    4 => 'street_name',
    5 => 'id'
    )
);
$router->addRoute('archive', $route);

它将子模式分配给变量,其中 1=> 是第一个子模式,2 是第二个子模式等。这些变量将在操作方法中可用,例如$this->_getParam('zipcode');您可以根据需要调整REGEX

于 2013-06-04T21:37:49.683 回答