2016-04-25 33 views
0

モジュールを使用して管理側でページを作成したいと思います。 hook_menu()を使ってカスタムリンクページについて言及する必要があります。ブラウザからリンクにアクセスした後、別のウェブサイトから別の静的リンクを呼び出すためのリンクを表示したい。例についてはdrupal 7でカスタムリンクを持つカスタムページを作成するには?

私は管理者/リストのリンクを作成したい:カスタムURL

この上でクリックした後は、このページには、結果はのナビゲーションのためのボタンで一覧表のようになりますその静的リンクは別のWebサイトから取得します。

私は以下を作成しました。

次のコードを使用して、カスタムテンプレートファイルの割り当て、渡された静的リンクによるカスタムページを作成し、カスタムテンプレートページに出力しました。注意してください、私はちょうどテンプレートページに配列を印刷しました。書式設定は残ります。

<?php 
    // Created Custom URL for accesing the static links 
    function test_menu() { 
     $items['admin/list-of-links'] = array(
      'title' => 'List Section', 
      'page callback' => 'list_section', 
      'access arguments' => array('administrator'), 
     ); 
    } 

    // Created Page Callback for assigning the variable for the theme 
    function list_section() { 
     $static_links = array("www.google.com", "www.facebook.com"); 
     return theme('test_link', array('static_links' => $static_links)); 
    } 

    // Assigned the template for the page that we have created 
    function test_theme($existing, $type, $theme, $path) { 

     return array(
      'test_link' => array(
       'template' => 'static-link-listing', 
       'path' => drupal_get_path('theme', 'seven') . "/templates" 
      ), 
     ); 
    } 

    //Created Template File : themes/seven/templates/static-link-listing.tpl.php 
    // And after that, I am getting the result. 
    // Now after that, we will format what output we need. 

    echo "<pre>"; 
    print_r($static_links); 

    ?> 

答えて

0

これを行うには、hook_menu()を使用する必要があります。

その後、あなたは.moduleファイルに次のコードを追加する必要があります、のは、例という名前のモジュールNISを言ってみましょう:

/** 
* Implements hook_menu(). 
*/ 
function example_menu() { 
    $items['admin/list-of-links'] = array(
    'description' => 'Load a list lof links', 
    'title' => t('List of links'), 
    'page callback' => '_example_load_links', 
    'access arguments' => array('access content'), 
    'type' => MENU_NORMAL_ITEM, 
); 

    return $items; 
} 

その後、選択されたページ上のリンクのリストを返すには、あなた'LL例えばので、ページのコールバックのための機能を追加する必要があります。

/** 
* We load a list of links 
*/ 
function _example_load_links(){ 
    $content['item'] = array(
    '#type' => 'item', 
    '#markup' => t('Hello world, place your links here'), 
); 
    return $content; 
} 

あなたのモジュールを有効にして(hook_menuで非常に重要な)あなたのキャッシュをクリアする場合、これは動作するはずです

関連する問題