2014-03-31 4 views
0

Ushahidi라는 플랫폼을위한 첫 번째 플러그인을 빌드하려고합니다. Ushahidi는 Kohana 프레임 워크를 사용하는 PHP 기반 플랫폼입니다.PHP 기반 플랫폼에서 후크로 DOM을 위로 이동

내가 여기 나에게 사용할 수있는 모든 후크를 찾고 있었어요 : https://wiki.ushahidi.com/display/WIKI/Plugin+Actions

내 목표는 웹 사이트가 더 검색하고 공유 할 수 있도록 특정 페이지의 헤더에 메타 태그를 추가하는 것입니다. 이 태그는 페이지의 내용에 따라 동적이지만, 지금은 "Hello World"를 올바른 위치로 가져 가고 싶습니다.

찾을 수있는 가장 가까운 고리가 올바른 페이지로 이동하지만 올바른 위치는 아닙니다. http://advance.trashswag.com/reports/view/1을 방문하면 "Hello World"라는 문자열을 페이지에 표시 할 수 있습니다. 1 단계 완료. 나를위한 2 단계는 hello world를 페이지 머리글에 표시하고 "view page source"를 사용하여 볼 수있게하는 것입니다. 내 함수에 따라 DOM을 백업 할 수있는 방법이 있습니까?

<?php 

class SearchShare{ 

    public function __construct(){ 
     //hook into routing 
     Event::add('system.pre_controller', array($this, 'SearchShare')); 
    } 

    public function SearchShare(){ 
     // This seems to be the part that tells the platform where to place the change. Presumably this is the part I'd need to edit to step up the DOM into the head section 
     Event::add('ushahidi_action.report_meta', array($this, 'AddMetaTags')); 
    } 

    public function AddMetaTags(){ 
     // just seeing if I can get any code to run 
     echo '<h1 style="font-size:70px;">Hello World</h1>'; 
    } 
} 
new SearchShare; 

?> 

답변

1

올바른 위치에 코드를 가져 오려면 다른 이벤트를 사용해야합니다. 당신은 장소의 몇 가지에 연결할 수 있습니다 :

  1. 사용 ushahidi_action.header_scripts 이벤트 :.

    Event::add('ushahidi_action.header_scripts', array($this, 'AddMetaTags'));

    그가에 후크 위치를 확인할 수 header.php를 참조

  2. 사용 ushahidi_filter.header_block 이벤트 :

    public function SearchShare(){ 
        Event::add('ushahidi_filter.header_block', array($this, 'AddMetaTags')); 
    } 
    public function AddMetaTags(){ 
        $header = Event::$data; 
        $header .= "Hello World"; 
        Event::$data = $header; 
    } 
    
    Themes.php을 참조하십시오.

어느 쪽이든 다른 쪽보다 좋거나 나쁘지 않으므로 선호하는 것을 사용하십시오.

+0

Brilliant! 정보 주셔서 감사 드리며 행운을 빌며 –