我想为 cck 字段(DateTime user_reference)调用 drupal_execute() 但它不会在数据库中保存任何内容
我有一个内容类型作为待办事项列表元素。它有一些 cck 字段,例如截止日期(日期时间格式)和分配的用户(用户参考字段)。我想使用函数 drupal_execute 以编程方式创建这样的节点,但是在出现了很多错误之后
警告:call_user_func_array() [function.call-user-func-array]:第一个参数应该是有效的回调,“views_access”在 ..includes/menu.inc 第 454 行给出。
并创建节点,其cck 值为 NULL。这是我的代码
$form_state = array();
$form_state['values'] = array(
'title' => $title,
'body' => $description,
'name' => $GLOBALS['user']->name,
'op' => t('Save'),
'field_deadline' => array(
0=> array('value'=>array('month'=>1,
'day'=>1,
'year'=>2011,
'hour'=> 1,
'minute'=> 1
))
),
'field_notification_time' => array(
0=> array('value'=>array('month'=>10,
'day'=>24,
'year'=>2010,
'hour'=> 0,
'minute'=> 24
))
),
'field_assign_user' => array(
0=> array(
'uid' => array( 'uid'=> 'user1')
)
),
);
$node = (object) array( '类型' => 'todo_element'); module_load_include('inc', 'node', 'node.pages');drupal_execute('todo_element_node_form', $form_state, $node);
I have a content type as a todo list element. It has some cck fields like deadline (in DateTime format) and assigned_user (a user reference field). I want to use function drupal_execute to create a such node programmatically, but after a full of errors like
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'views_access' was given in ..includes/menu.inc on line 454.
and creating the node, its cck values are NULL. this is my code
$form_state = array();
$form_state['values'] = array(
'title' => $title,
'body' => $description,
'name' => $GLOBALS['user']->name,
'op' => t('Save'),
'field_deadline' => array(
0=> array('value'=>array('month'=>1,
'day'=>1,
'year'=>2011,
'hour'=> 1,
'minute'=> 1
))
),
'field_notification_time' => array(
0=> array('value'=>array('month'=>10,
'day'=>24,
'year'=>2010,
'hour'=> 0,
'minute'=> 24
))
),
'field_assign_user' => array(
0=> array(
'uid' => array( 'uid'=> 'user1')
)
),
);
$node = (object) array(
'type' => 'todo_element'); module_load_include('inc', 'node', 'node.pages');drupal_execute('todo_element_node_form', $form_state, $node);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要使用 drupal_execute。您可以根据需要创建节点对象,然后调用:
node save 然后将调用 CCK 要求将字段正确保存在数据库中。
you don't need to use drupal_execute. You can create your node object as you want and at the and you invoke:
node save then will call CCK to ask to save the field correctly in the DB.