:($this->_redirect($newURL);
あなたのコントローラ内)Redirector
ヘルパーに渡しますこのパラメータが常に表示されていることを確認したい場合は、パラメータがコントローラに設定されているかどうかを確認し、欠落している場合はリダイレクトを発行する必要があります。だから、
、ブートストラップファイルに:あなたはこのルートを持っていることを、あなたはそのようなあなたのビューでそれを使用することができます
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _initRoutes()
{
// Ensure that the FrontController has been bootstrapped:
$this->bootstrap('FrontController');
$fc = $this->getResource('FrontController');
/* @var $router Zend_Controller_Router_Rewrite */
$router = $fc->getRouter();
$router->addRoutes(array (
'question' => new Zend_Controller_Router_Route (
/* :controller and :action are special parameters, and corresponds to
* the controller and action that will be executed.
* We also say that we should have two additional parameters:
* :question_id and :title. Finally, we say that anything else in
* the url should be mapped by the standard {name}/{value}
*/
':controller/:action/:question_id/:title/*',
// This argument provides the default values for the route. We want
// to allow empty titles, so we set the default value to an empty
// string
array (
'controller' => 'question',
'action' => 'show',
'title' => ''
),
// This arguments contains the contraints for the route parameters.
// In this case, we say that question_id must consist of 1 or more
// digits and nothing else.
array (
'question_id' => '\d+'
)
)
));
}
}
:今、あなたのコントローラで
<?php echo $this->url(
array(
'question_id' => $this->question['id'],
'title' => $this->question['title']
),
'question'
);
// Will output something like: /question/show/123/my-question-title
?>
、あなたが確認する必要がありますtitle-parameterが設定されているか、そうでない場合はタイトルセットを使用して自身にリダイレクトする:
public function showAction()
{
$question = $this->getQuestion($this->_getParam('question_id'));
if(!$this->_getParam('title', false)) {
$this->_helper->Redirector
->setCode(301) // Tell the client that this resource is permanently
// residing under the full URL
->gotoRouteAndExit(
array(
'question_id' => $question['id'],
'title' => $question['title']
)
);
}
[... Rest of your code ...]
}
詳細についてはPatrikにお問い合わせください。あなたがコントローラーに加えた変更についてはわかりません。すべての私の見解では、タイトルをURLの一部として設定していますが、タイトルなしでwww.example.com/question/show/123というURLを入力するだけで。しかし、私が望むのは、ユーザーが上記のURLをタイプしても、ページがレンダリングされたときでも、URLにはタイトルが付いているはずです。 stackoverflowのようにhttp://stackoverflow.com/questions/5451200/を入力すると、タイトルが自動的に追加されます。それで、あなたがここでコントローラーでやっていることです。 – Gublooo
ええ、提供するタイトルはオプションですが、提供されていない場合、コントローラは同じURLに301の恒久リダイレクトを行いますが、タイトルは追加されます。あなたはリダイレクトを行う必要があります、あなたはURLの外観を変更することはできません。 – PatrikAkerstrand
ohありがとう私はちょうどあなたの返事を見ました - だから私はコントローラにそのコードを追加する - 私はホームページにリダイレクトされています。 – Gublooo