2016-04-25 50 views
0

我想使用模塊在管理端創建頁面。我需要使用hook_menu()來提到自定義鏈接頁面。從瀏覽器訪問鏈接後,我想顯示一些鏈接,以便從另一個網站調用另一個靜態鏈接。如何在drupal 7中創建具有自定義鏈接的自定義頁面?

例如:

我想創建一個管理員/列表的鏈接:自定義網址

點擊此之後,這個頁面上,其結果必然是像表按鈕,列出的導航來自另一個網站的靜態鏈接。

我創建了以下內容。

通過使用以下代碼,我創建了具有自定義模板文件分配的自定義頁面,通過傳遞靜態鏈接並將其打印在自定義模板頁面中。請注意,我剛剛在模板頁面上打印了數組。格式是剩餘的。

<?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()來執行此操作。

比方說,你的模塊NIS命名爲例子,那麼你就需要在.module文件中添加以下代碼:

/** 
* 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; 
} 

要那麼選擇頁面上返回的鏈接列表,你會需要添加功能的頁面回調,因此,例如:

/** 
* 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非常重要)這應該工作