php – Drupal 7 – 自定义查看与自定义表,没有数据显示

前端之家收集整理的这篇文章主要介绍了php – Drupal 7 – 自定义查看与自定义表,没有数据显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我写了一个模块来使用Drupal 7与Views 3进行接口,但是当我使用自定义表格作为数据源创建一个视图时,没有数据显示.这是 MySQL的架构
+-------------+------------+------+-----+---------+----------------+
| Field       | Type       | Null | Key | Default | Extra          |
+-------------+------------+------+-----+---------+----------------+
| id          | int(11)    | NO   | PRI | NULL    | auto_increment |
| title       | mediumtext | NO   |     | NULL    |                |
| Department  | text       | NO   |     | NULL    |                |
| credits     | int(10)    | NO   |     | NULL    |                |
| description | longtext   | NO   |     | NULL    |                |
+-------------+------------+------+-----+---------+----------------+

这是my_module.views.inc中的钩子覆盖:

function my_module_views_data() {
  $tableName = 'My_Awesome_Table';
  $data = array();
  $data[$tableName]['table']['group'] = t('Courses');

  $data[$tableName]['table']['base'] = array(
    'field' => 'id','title' => t('Courses'),'help' => t("Contains courses,departments,and descriptions.")
  );

  $data[$tableName]['title'] = array(
    'title' => t('Course name'),'help' => t('Course name'),'field' => array(
      'handler' => 'views_handler_field','click sortable' => TRUE,),'sort' => array(
      'handler' => 'views_handler_sort','filter' => array(
      'handler' => 'views_handler_filter_string','argument' => array(
      'handler' => 'views_handler_argument_string',);

  $data[$tableName]['Department'] = array(
    'title' => t('Course department'),'help' => t('Course department'),);

  $data[$tableName]['credits'] = array(
    'title' => t('Credits'),'help' => t('Number of credit hours'),'argument' => array('handler' => 'views_handler_argument_numeric'),'filter' => array('handler' => 'views_handler_filter_numeric'),'sort' => array('handler' => 'views_handler_sort_numeric')
  );

  $data[$tableName]['description'] = array(
    'title' => t('Course description'),'help' => t('Course description'),);

  $data[$tableName]['id'] = array(
    'title' => t('Unique identifier'),'help' => t('Primary key for table'),'field' => array('handler' => 'views_handler_field'),'sort' => array('handler' => 'views_handler_sort_numeric'));

  return $data;
}

我的映射有什么问题吗?当我创建一个视图时,我正在尝试一个简单的无格式列表,并只显示每个字段的标签.显示数据的唯一字段是id,我表中的所有id值都在那里.我尝试向视图添加过滤器,以便课程部门!=空白和课程名称!=空白,这不会消除任何结果(基于显示的ids).这是查询视图正在生成

SELECT My_Awesome_Table.title AS My_Awesome_Table_title,My_Awesome_Table.Department AS My_Awesome_Table_Department,My_Awesome_Table.description AS My_Awesome_Table_description,My_Awesome_Table.credits AS My_Awesome_Table_credits,My_Awesome_Table.id AS id
FROM {My_Awesome_Table} My_Awesome_Table
WHERE (( (My_Awesome_Table.Department NOT LIKE '' ESCAPE '\\') AND
  (My_Awesome_Table.title NOT LIKE '' ESCAPE '\\') ))

当我在PHPMyAdmin中运行它时,只需从My_Awesome_Table周围删除{和},它返回结果,每列中都有数据.

编辑:这可能与我在另一个数据库中为另一个表另外创建了一个自定义View模块相关联,它的工作正常.我使用该模块作为这个模块的基础,更改模块名称,函数前缀等.

清除缓存,禁用模块’my_module’,保存,然后启用它,保存

在我的开发中,我必须添加这个钩子使其工作

function my_module_views_api() {
    return array('api'=>2.0);
}
原文链接:https://www.f2er.com/php/138756.html

猜你在找的PHP相关文章