我在 drupal 中创建了一个带有实体的自定义模块。我已经安装了实体 api 模块。通过employee_management.install 文件(其中employee_management 是我的自定义模块名称)和employee 是我的实体名称,我创建了只有两列(employee_id,first_name)的数据库模式。
我还编写了必要的函数employee_management.module,但它仍然显示错误,每当我尝试在管理员/结构/员工中添加新实体时,它都会显示以下错误:“未找到”。
在此服务器上找不到请求的 URL drupal/employee/add/。
function employee_management_entity_info() {
$employee_info['employee'] = array(
// A human readable label to identify our entity.
'label' => t('Employee Entity'),
// The controller for our Entity - extends the Drupal core controller.
'controller class' => 'EmployeeController',
// The table defined in hook_schema()
'base table' => 'employee',
// Returns the uri elements of an entity
'uri callback' => 'employee',
// Fieldable that we can attach fields to it - the core functionality will
// do the heavy lifting here.
'fieldable' => TRUE,
// The unique key of our base table.
'entity keys' => array(
'id' => 'employee_id',
),
// FALSE disables caching - caching functionality is handled by Drupal core
'static cache' => TRUE,
// Attach bundles - i.e. alternative configurations of fields associated with a main entity.
'bundles' => array(
'employee' => array(
'label' => 'Employee',
// Information below is used by the Field UI - they "attach" themselves here and lets us
// do the standard field management that all the core entities enjoy.
'admin' => array(
'path' => 'admin/structure/employee/add',
'access arguments' => array('administer employee entities'),
),
),
),
// View modes allow entities to be displayed differently based on context. We simply have one option
// here but an alternative would be to have a Full and Teaser mode akin to node.
'view modes' => array(
'full' => array(
'label' => t('Full'),
'custom settings' => FALSE,
),
)
);
return $employee_info;
}
编辑
function employee_uri($employee) {
return array(
'path' => 'employee/' . $employee->employee_id,
);
}
这是文件employee_management.module中的完整功能列表