2013-08-20 2 views
0

나는 두 가지 모델joomla 모델에서 event_before_delete 트리거를 작성하는 방법은 무엇입니까?

  1. 갤러리
  2. 이미지를

내가 디렉토리에 관련 이미지를 기록 ANS 이미지를 삭제 한 다음 갤러리 개체와 디렉토리를 삭제할 갤러리를 삭제하는 동안.

최상의 선택은 onBeforeContentDelete 트리거 인 것 같습니다. 플러그인을 작성해야합니다. 그러나 모든 플러그인 생성 단계를 거치고 싶지는 않습니다.

이렇게 삭제할 수 있습니까? 당신의 자신의 구성 요소 당신에게 만약 내가 config 배열에 이벤트 이름은 예에게 전달 될 수 있음을 알 수 JModelAdmin 코어 클래스를 통해가는

class SomePrefixModelGallery extends JModelAdmin 
{ 
    public function __construct($config=array()) 
    { 
     parent::__construct($config); 
    } 

    public function onBeforeGalleryDelete($context,$table){ 
     if($this->deleteAllImages()){ 
      $this->removeDir($this->folder); 
      return true; 
     } 
     else 
     return false; 
    } 

    public function deleteAllImages(){ 
     // get Image model and delete all images 
    } 
} 

`array('event_before_delete'=>'onXYZEventName')` 

기본 이벤트 세트는 onBeforeContentDelete

답변

2

입니다 모델의 delete 메소드를 무시할 수 있습니다. 플러그인이 필요하지 않습니다.

JModelAdmindelete() 방법이있다, 그래서 당신의 모델에 : 내가 한

class SomePrefixModelGallery extends JModelAdmin 
{ 
     /* all the standard methods */ 

    /** 
     * Method to delete one or more records. 
     * 
     * @param array &$pks An array of record primary keys. 
     * 
     * @return boolean True if successful, false if an error occurs. 
     * 
     * @since 11.1 
     */ 
    public function delete(&$pks) 
    { 
     // Code to delete your image records 

     // Code to delete your image files 

     // Call the parent delete to remove the Gallery entry 
     parent::delete(&$pks); 
    } 
} 
+0

덕분에이 방법을 수행하는 관리 할 수 ​​있습니다. 그러나 나는 사건을 통해 관리 할 수있는 방법을 찾고있었습니다. 그것은 이벤트를 통해 이것을 처리하기 위해 구성 요소 및 해당 모델에 대한 콘텐츠 플러그인을 작성해야만하는 것 같습니다. – sakhunzai

관련 문제