Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
drupal模块页面_Drupal_Drupal 6_Module - Fatal编程技术网

drupal模块页面

drupal模块页面,drupal,drupal-6,module,Drupal,Drupal 6,Module,我遇到了一个概念上的障碍。 所以,我想制作一个定制的Drupal模块,有几个不同的页面,每个页面都“做一些事情” 我不了解如何将不同的页面制作/集成到我的模块中,以及它们的URL是什么 我确实有这个: /* FILE : mymodule.module */ function mymodule_menu() { $items = array(); $items['mymodule/landingpage'] = array( 'page callback' =&g

我遇到了一个概念上的障碍。 所以,我想制作一个定制的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\u landing()生成的内容

但这似乎不是我想要做的,因为登陆页面的内容是在
mymodule.module
中生成的,这让我对如何制作我的
mysite.com/mymodule/step2
mysite.com/mymodule/step99
pages

我有一种直觉,每个页面的代码都应该在它自己的对应文件中,我不知道该怎么做,这似乎不是正确的方法


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

到目前为止,你所做的大部分都是正确的(“title”键对于每个项目都是必需的,所以一定要包括在内)。由于
页面回调
指向
mymodule\u landing()
,因此从该函数返回的内容将在页面上显示为您的内容

要创建更多页面(如step2、step99等),您可以继续在
mymodule\u menu()
中创建更多路径,如:

$items['mymodule/step2'] = array( 
  'title' => 'Step 2',  // Required
  'page callback' => 'mymodule_step2',
  'access arguments' => array('access content'),
  'type' => MENU_NORMAL_ITEM,
); 
等等。。。您可以使用相同的页面回调
mymodule\u landing()
,只需传递“页面参数”,或者每个页面都可以有自己的页面回调

要将函数
mymodule\u landing()
放在一个单独的文件中,可以使用文件和文件路径键(见下文)

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

页面处理程序的最佳实践包括文件(更多信息请访问):

模块开发人员可以根据自己的选择自由地分离模块的页面处理程序。但是,建议采用以下指南和标准:

  • 对于页面处理函数(包括表单处理函数,如果适用),任何具有超过50行代码的模块都应将其拆分为单独的文件。这减少了加载模块时PHP的开销,因此加快了站点上的每个请求
  • 页面包含文件应以modulename.key.inc的形式命名,其中“modulename”是模块的名称,“key”是它包含的页面处理程序类型的一个单词描述性术语
  • 对于大多数模块,将页面处理程序拆分为两个文件——example.admin.inc(仅适用于管理员页面)和example.pages.inc(适用于非管理员用户可访问的页面)——就足够了,这是推荐的做法。如果模块没有非管理员页面,它应该只有一个example.admin.inc文件。如果模块没有仅限管理员的页面,那么它应该只有一个example.pages.inc文件
  • 具有大量页面处理程序的模块可以选择进一步分离页面处理程序。如果是这样,每个文件都应该按功能进行逻辑分组(例如,与主题相关的管理页面、与日志相关的管理页面、其他管理页面和用户可访问的页面),并明确标记。请记住,将模块的页面处理程序分割得太远会使维护变得更加困难,并且无论处理程序函数的粒度有多细,都只会加载一个页面处理程序include文件
新增内容仅供参考:

这也可能对你有所帮助

 $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'),
 );