gpt4 book ai didi

drupal 模块页面

转载 作者:行者123 更新时间:2023-12-04 14:05:53 25 4
gpt4 key购买 nike

我遇到了一种概念上的障碍。
所以,我想制作一个自定义的 Drupal 模块,它有几个不同的页面,每个页面都“做事”。

我不了解如何将不同的页面制作/集成到我的模块中,以及它们的 URL 是什么。

我有这个:

 /* FILE : mymodule.module */
function mymodule_menu() {

$items = array();
$items['mymodule/landingpage'] = array(
'page callback' => 'mymodule_landing',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}

function mymodule_landing() {

$title = 'Hello World';
$content ='This is a simple Hello World Proof of Concept';
return theme_box($tile, $content);
}

当我去 mysite.com/mymodule/landingpage ,我看到 mymodule_landing()生成的内容.

但这似乎不是我想做的,因为 landingpage 的内容在 mymodule.module 内部生成,这让我对如何制作我的 mysite.com/mymodule/step2 感到非常困惑, ... , mysite.com/mymodule/step99页面

我有直觉认为每个页面的代码都应该在它自己的相应文件中,我不明白该怎么做,这似乎不是正确的方法。

你能解释一下我应该怎么做,文件应该去哪里(和我的其他模块文件,对吧?),以及它可以在哪个 URL 上查看?

最佳答案

到目前为止,您所做的大部分都是正确的(“标题”键是 每个项目都需要 ,因此请务必包括在内)。由于page callback针对mymodule_landing() ,从该函数返回的内容将作为您的内容显示在页面上。

要制作更多页面(如 step2、step99 等),您将继续在 mymodule_menu() 中创建更多路径。像:

$items['mymodule/step2'] = array( 
'title' => 'Step 2', // Required
'page callback' => 'mymodule_step2',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);

等等...您可以使用相同的页面回调 mymodule_landing()并简单地传递“页面参数”或者每个都可以有自己的页面回调。

把你的功能 mymodule_landing()在单独的文件中,您可以使用文件和文件路径键(见下文)
 $items['mymodule/landingpage'] = array( 
'title' => 'Landing Page', // Required
'page callback' => 'mymodule_landing',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
'file' => 'mymodule.pages.inc',
'file path' => drupal_get_path('module', 'mymodule'),
);

您应该将这些文件放在您的模块目录(或模块目录内的子目录并设置正确的文件路径)中,并且可以在 mysite.com/mymodule/landingpage访问每个页面, mysite.com/mymodule/step2 , ETC。

页面处理程序包含文件的最佳实践 (在 http://drupal.org/node/146172 上阅读更多信息):

Module developers are free to split off page handlers for their modules however they choose. However, the following guidelines and standards are recommended:

  • Any module that has more than ~50 lines of code for page handler functions (including form handling functions if applicable) should split them off into a separate file. That reduces the overhead for PHP when loading modules, and therefore speeds up every single request on the site.
  • Page include files should be named in the form modulename.key.inc, where "modulename" is the name of the module and "key" is a one-word descriptive term for the types of page handlers it includes.
  • For most modules, splitting page handlers into two files -- example.admin.inc (for administrator-only pages) and example.pages.inc (for pages accessible by non-administrator users) -- is sufficient, and is the recommended practice. If a module has no non-administrator pages, it should just have a single example.admin.inc file. If a module has no administrator-only pages, it should just have a single example.pages.inc file.
  • Modules that have a large number of page handlers may choose to separate out page handlers even further. If so, each file should be grouped logically by function (for instance, admin pages related to theming, admin pages related to logging, other admin pages, and user-accessible pages) and clearly marked. Remember that splitting the module's page handlers up too far makes maintenance more difficult, and only one page handler include file is ever loaded regardless of how finely-grained the handler functions are separated.


添加仅供引用: hook_menu() documentation

page_example.module也可能对你有帮助。

关于drupal 模块页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5345484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com