English 中文(简体)
symfony: permalinks
原标题:symfony: permalinks (hide id in urls)

I ve read the paragraph about permalinks (hide primary keys and replace them with significant strings) but I can t understand how it works this code:

public function executePermalink($request)
  {
    $article = ArticlePeer::retrieveBySlug($request->getParameter( slug );
    $this->forward404Unless($article);  // Display 404 if no article matches slug
    $this->article = $article;          // Pass the object to the template
  }

该法典是推进剂的典型,是否正确? 这与理论一样? 我要写一下检索的BySlug()功能? 你们有了一个例子,我可以理解如何写字?

感谢很多人

最佳回答

在理论中,你可以使用一种称为“易腐”的延伸。

为了使其发挥作用,必须改变你的表象,并增加“可比较”的延伸:

# config/doctrine/schema.yml
Article:
  actAs:
    Timestampable: ~
    Sluggable:
      fields: [name]
  columns:
    name:
      type: string(255)
      notnull:  true

在您的行程中设置一条理论。 页: 1

# apps/frontend/config/routing.yml
category:
  url:      /article/:slug
  class:    sfDoctrineRoute
  param:    { module: article, action: show }
  options:  { model: Article, type: object }

在你的行动守则中,你可以做这样的事情:

public function executeShow(sfWebRequest $request)
{
    $this->article = $this->getRoute()->getObject();
    $this->forward404Unless($article);  // Display 404 if no article matches slug
    $this->article = $article;          // Pass the object to the template
}

Don tabes toî a theory:build to recreate the database after You schema.

问题回答

如今,正在做罚款。

# apps/frontend/config/routing.yml
opera_slug:
  url:   /:sf_culture/opere/:operaslug.html
  class:    sfDoctrineRoute
  param: { module: opera, action: permalink }
  options:  { model: Opera, type: object }
  requirements:
    sf_culture: (?:it|en|es|fr)



  public function executePermalink(sfWebRequest $request)
  {  
    $this->opera = $this->getRoute()->getObject();
    $this->forward404Unless($this->opera);  // Display 404 if no article matches slug
    //$this->opera = $opera;          // Pass the object to the template  
  }  

如你所知,我修改了执行Permalink(Permalink)的两行,因为我使用你的职能有错误。





相关问题
Converting GET method url s to logical permanent links

I have a J2EE application with a web service which goes like http://servername/service?task=getFile&id=25 How can I convert these type of urls to http://servername/service/getFile/25 http://...

wordpress permalink post_type

i am looking for a way to get the post_type into a wordpress permalink structure - especially considering custom post_type s defined by my own plugin. is there an easy way to do that, or do you know ...

.htaccess gone for deleted, permalink database entries

I have event entries in a php application with a permalink structure for the events. I m creating a dynamic xml sitemap for google et al. which creates new url nodes as events are added, and when an ...

Wordpress stop post redirects

I m having a Wordpress problem regarding permalinks. When I have a post whose permalink is say, /2009/10/podcasts, trying to access /podcasts redirects to /2009/10/podcasts. Is there any way to stop ...

Recommended url structure for parent child list in mvc

If I am listing child items of a parent in an asp.net mvc app, is there a best practice to how the url structure should be formed? Example: 1. http://app/parent/<parentID>/children 2. http://...

Rails Friendly URLs

I have a model called Project and I ve defined the "to_param" method as this: def to_param permalink end I am using this permalink plugin github.com/febuiles/make_permalink so when I call p....

Permalink/slug best practices

I m about to setup permalinks on a website and I m wondering what sort of conventions I should follow in regards to generating them from the existing table of news articles. So far here are the rules/...

热门标签