drupal问题汇总

用drupal_substr限制drupa标题长度

一、参数arguments => array(1)或者array(2)是啥意思?(传递变量值)

二、arg(1)arg(4)是啥意思?(返回当前的路径)

例:When viewing a page at the path "admin/content/types", for example, arg(0) would return "admin", arg(1) would return "content", and arg(2) would return "types".

http://api.drupal.org/api/drupal/includes--path.inc/function/arg/6

三、form表单中的 ‘#type’ => 'value'是啥意思?如:

             $form['v'] = array(
                       '#type' => 'value',
                      '#value' => $v,
                  );(应该是值传递)

四、hook_menu路径中的%(半明白)

 

五、variable_get总是一直用,而variable_set很少用。why?

六、hook_user需要再加深理解

http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_user/6

http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_link/6

 

 

http://zhupou.cn/book/export/html/174

 

如何在个人账户增加tab标签:需要在hook_menu函数里增加路径(user/%user_uid_optional/XXXX),然后'type' => MENU_LOCAL_TASK

如何在个人账户的历史里增加内容:

function photos_user($op, &$edit, &$ac) {
  global $user;
  switch ($op){
    case 'view':

$item[] = l(t("地址1"),"xxxx");

$item[] = l(t("地址2"),"xxxx");

$item[] = l(t("地址3"),"xxxx");

 

 

$ac->content['summary']['xiang'] =  array(  //xiang为自由增加
          '#type' => 'user_profile_item',
          '#title' => t('标题'),
          '#value' => theme('item_list', $item),
          '#attributes' => array('class' => 'chen'),//chen为增加的CSS类
         );

 

 

如何在添加评论右侧添加链接:hook_link($type, $object, $teaser = FALSE){

$links = array();

if($node->type == 'story'){
 $title = t('添加注释');
 }
 $links['zhushi'] = array(
 'title' => $title,
 'href' => "ddddddd",
 );

return $links;

}

 

 <?php
function hook_link($type, $object, $teaser = FALSE) {
  $links = array();

 

  if ($type == 'node' && isset($object->parent)) {
    if (!$teaser) {
      if (book_access('create', $object)) {
        $links['book_add_child'] = array(
          'title' => t('add child page'),
          'href' => "node/add/book/parent/$object->nid",
        );
      }
      if (user_access('see printer-friendly version')) {
        $links['book_printer'] = array(
          'title' => t('printer-friendly version'),
          'href' => 'book/export/html/' . $object->nid,
          'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')),
        );
      }
    }
  }

 

  $links['sample_link'] = array(
    'title' => t('go somewhere'),
    'href' => 'node/add',
    'query' => 'foo=bar',
    'fragment' => 'anchorname',
    'attributes' => array('title' => t('go to another page')),
  );

 

  // Example of a link that's not an anchor
  if ($type == 'video') {
    if (variable_get('video_playcounter', 1) && user_access('view play counter')) {
      $links['play_counter'] = array(
        'title' => format_plural($object->play_counter, '1 play', '@count plays'),
      );
    }
  }

 

  return $links;
}
?>

 

 

 

<?php
function hook_link($type, $object, $teaser = FALSE
) {
 
$links
= array();

  if (
$object->type == 'video' && $object->name) {
   
$links['sample_link'
] = array(
     
'title' => 'Videos by ' . $object->name,
     
'href' => 'user/' . $object->uid
,
     
'query' => 'quicktabs_1=0'
,
     
'fragment' => 'quicktabs'
,
    );
  }

  return
$links
;
}

 

 

 

 
 
hook_link_alter(&$links, $node)

 

修改注册表单:

hook_user($op, &$edit, &$ac){

case 'register':
 
 $fields['personal_profile'] = array(
    '#type' => 'fieldset',
    '#title' => '个人资料(可选)',
  );
  $fields['personal_profile']['sex'] = array(
    '#title' => '性别',
    '#type' => 'radios',
    '#default_value' => 0,
    '#options' => array('男' , '女')
  );
  $fields['personal_profile']['address'] = array(
    '#type' => 'textfield',
    '#title' => '现居住地址',
  );
  
  $fields['personal_profile']['introduction'] = array('#title' => '个人介绍', '#type' => 'textarea', '#rows' => 5, '#cols' => 50);
  
  return $fields;

 

case 'form':
  $fields['personal_profile'] = array(
    '#type' => 'fieldset',
    '#title' => '个人资料(可选)',
    '#weight' => 1,
  );
  $fields['personal_profile']['sex'] = array(
    '#title' => '性别',
    '#type' => 'radios',
    '#default_value' => 0,
    '#options' => array('男' , '女'),
    '#default_value' => $user->sex,
  );
  $fields['personal_profile']['address'] = array(
    '#type' => 'textfield',
    '#title' => '现居住地址',
    '#default_value' => $user->address,
  );
 
  $fields['personal_profile']['introduction'] = array(
    '#title' => '个人介绍',
    '#type' => 'textarea',
    '#rows' => 5,
    '#cols' => 50,
    '#default_value' => $user->introduction
  );
  return $fields;
  break;
 

其中的register这个op控制用户注册表单,而form这个op控制用户编辑自己个人资料的表单。form只是比register加入了一些默认值而已,而这些默认值是从登录用户的user对象中读取的,很简单吧。

最后,如果你只是一个drupal使用者,不妨可以使用drupal内置的profile模块,手动配置和添加,更方便。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值