2017-01-24 5 views
0

고객 컨트롤러에 양식이 있습니다. 내가 원하는 것은 다른 컨트롤러의 폼을 동일한 고객 페이지에 추가하는 것입니다. iFrame을 사용하여 Silverstripe 바에서이 작업을 수행 할 수 있습니까?실버 스트라이프 - 컨트롤러 내에 컨트롤러 포함

+0

, 당신은 다른 템플릿에서 것을 포함 할 수 있습니다, 네 –

답변

1

음, 그래도 코드에 약간의 수정이 필요할 수 있습니다.

목표 달성 내가 생각할 수있는 두 주요 방법이 있습니다 :

class Foo extends Controller { 
    private static $allowed_actions = ['FooForm', 'BarForm']; 

    public function FooForm() { 
     return new Form($this, __FUNCTION, new FieldList(), new FieldList()); 
    } 

    public function BarForm() { 
     return Bar::get_bar_form($this, __FUNCTION__); 
    } 
} 

class Bar extends Controller { 
    private static $allowed_actions = ['BarForm']; 

    public function BarForm() { 
     return static::get_bar_form($this, __FUNCTION__); 
    } 

    /** 
    * A static function that accepts the controller (Bar or Foo in this case) and a name 
    * This way, this form can easily be used on other controllers as well 
    * Just be aware that this way, the Forms controller is not always the same, so if you have a custom form that calls specific methods of the Bar controller this will not work 
    */ 
    public static function get_bar_form($controller, $name) { 
     return new Form($controller, $name, new FieldList(), new FieldList()); 
    } 
} 

2. 중첩 된 컨트롤러 :

1. 컨트롤러 액션에서 양식 작성을 분리은

SilverStripe에서는 컨트롤러를 중첩 할 수 있습니다. 이것은 본질적으로 Forms가 이미 수행하고있는 것입니다. SilverStripe 양식은 Controller (또는 RequestHandler)입니다.
SilverStripe에서 어떤 Controller 조치도 처리 할 수있는 다른 RequestHandler (Controller은 하위 클래스 인 RequestHandler)을 반환 할 수 있습니다.

그래서 Foo 컨트롤러 내에서 전체 Bar 컨트롤러를 반환하고 하위 컨트롤러로 실행할 수 있습니다. 따라서 URL은 /foo/bar/BarForm 일 수 있습니다.
표준 컨트롤러를 사용하면 중첩 된 URL을 갖기 위해 약간의 조정이 필요할 것입니다.

는 양식과 중첩 된 컨트롤러의 고급 예를 들어 내 ContentBlock/PageBuilder 모듈에서보세요 : 당신이 그 형태에 대해 "포함"템플릿이있는 경우
PageBuilder_Field.php#L179
PageBuilder_Field_Handler_Block.php#L32