私はSilverStripe 3.3.1を使用しており、多くのパラメータを持つURLを処理するカスタムルートを設定しています。それは動作します。Silverstripe:カスタムルートでコントローラのページフィールドにアクセスできません
ただし、ルーティングルールにより、Page_Controllerとテンプレートでページフィールドと関数にアクセスできなくなります。任意のアイデアをどのようにこれを修正するには?この質問はまたSilverstripeフォーラムに掲載されて
Director:
rules:
'mypage': 'MyPage_Controller'
config.ymlで
//MyPage class
class MyPage extends Page {
//Not accessible if route to controller specified in config.yml
private static $db = array(
'MyPageVar' => 'Int',
);
//Not accessible if route to controller specified in config.yml
public function getMySpecialVar() {
return $this->MyPageVar;
}
}
//MyPage_Controller class
class MyPage_Controller extends Page_Controller {
private static $allowed_actions = array(
'index',
'detailsearch',
);
private static $url_handlers = array (
'detailsearch/$Key1/$Value1/$Key2/$Value2/$Key3/$Value3/$Key4/$Value4/$Key5/$Value5' => 'detailsearch',
);
/**
* UseMyPageVar()
*
* @return Boolean
*/
public function UseMyPageVar() {
//Empty if route to controller specified in config.yml
Debug::show($this->MyPageVar);
Debug::show($this->Title);
Debug::show($this->Content);
//Error if route to controller specified in config.yml
Debug::show($this->getMySpecialVar());
return true;
}
}
MyPage.ss
<!-- This work as expected if no route is specified. -->
<!-- But all vars are empty if route is specified in config.yml -->
<p>MyVar: $MyPageVar</p>
<p>Title: $Title</p>
<p>Content: $Content</p>
ルーティングルール:それはかなりではありません http://www.silverstripe.org/community/forums/general-questions/editpost/413506
ご返信ありがとうございます。 1)ルーティングとURLハンドラーは期待どおりに動作します。問題は、コントローラとテンプレートのページフィールドにアクセスすることです。 2)私はroutes.ymlにルーティングルールを移動しました。ルーティングは引き続き機能しますが、コントローラでページ・フィールドにはまだアクセスできません。 3)ルーティングは既にソートされていました。コントローラのPageクラスに失われた参照をデバッグする必要がありました。 – cmc