2014-03-31 51 views
0

我試圖爲一個名爲Ushahidi的平臺構建我的第一個插件。 Ushahidi是一個使用Kohana框架的基於PHP的平臺。向上移動一個基於php的平臺的鉤子

我看着都提供給我這裏的鉤子:https://wiki.ushahidi.com/display/WIKI/Plugin+Actions

我的目標是meta標籤添加到某些頁面的標題,以幫助使網站更加搜索和共享。這些標籤將基於頁面內容動態變化,但現在我只想將「Hello World」放到正確的位置。

我能找到的最接近的鉤子將我帶到正確的頁面,但不是正確的地方。如果您訪問http://advance.trashswag.com/reports/view/1我已經設法讓字符串「Hello World」出現在頁面上。第一步完成 - 太棒了。對我來說,第2步是讓你好世界出現在頁面的標題中,所以只能使用「查看頁面源」查看。有沒有一種方法,我可以退後一步了基於我的功能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

太棒了!感謝您的信息,並祝我好運 –