开发者

Using the $object in Actions.I've created a module but parameter _action($object) is not work

Using the $object in Actions. $object: Many actions act on one of Drupal’s built-in objects: nodes, users, taxonomy terms, and so on. When an action is executed by trigger.module, the object that is currently being acted upon is passed along to the action in the $object parameter. For example, if an action is set to execute when a new node is created, the $object parameter will contain the node object. $object haven't value.i will get node's title and use in code.

function beep_action($object, $context) {
    global $user;
    //$q_mailfrom = db_query("SELECT mail FROM {users} WHERE uid = '%d'", 1);
   // $f_mailfrom = db_fetch_object($q_mailfrom);

    $q_mailuser = db_query("SELECT uid, mail  FROM {users}");
   // $a_mailto=array();
  //  $i=0;
    while($f_mailuser = db_fetch_object($q_mailuser)){
        if($f_mailuser->uid==1){
         $mailfrom = $f_mailuser->mail;
        }
     $q_mailer = db_query("SELECT news,proudcts,privilagecard,occassioncard,others开发者_运维问答  FROM {beep} WHERE uid = '%d'", $f_mailuser->uid);
     $f_mailer = db_fetch_object($q_mailer);
     if($f_mailer->news==1 OR $f_mailer->proudcts==1 OR $f_mailer->privilagecard==1 OR $f_mailer->occassioncard==1 OR $f_mailer->others==1 ){
        if($f_mailer->news==1){

            $mailto = $f_mailuser->mail;

            $subject = "... Group";
            $message = "<h2>... Group Latest News </h2>".$object->nid."<br/>Test";
            drupal_mail('beep', 'reply', $mailto, language_default(),
                 array('body' => $message, 'subject' => $subject), $mailfrom, TRUE);
        }
      //   $a_mailto[$i]= $f_mailto->mail;
      //  $i++;
     }
    }

}


I see what you want

function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
  switch($op){
    case 'insert':
      if($node->type == 'mytype'){
        beep_action($node);
      }
      break;
  }
}


Show call function. What you post in $object ?

And read drupal code stantarts.

function beep_action($object, $context) {
  _vdump($object);
  global $user;
  $default_from = variable_get('site_mail', ini_get('sendmail_from'));

  $query = "SELECT user.uid, user.mail  FROM {users} user WHERE status <> %d";

  $result = db_query($query, 0);
  $subject = t("Azaran Mehr Group");

  while ($row = db_fetch_object($result)) {
    $query = "SELECT beep.news, beep.proudcts, beep.privilagecard, beep.occassioncard, beep.others FROM {beep} beep WHERE uid = %d"; // Do not use ' on integer values

    $f_mailer = db_fetch_object(db_query($query, $row->uid));
    if ($f_mailer->news == 1 && ($f_mailer->proudcts == 1 || $f_mailer->privilagecard == 1 || $f_mailer->occassioncard == 1 || $f_mailer->others == 1)) {
      $message = '<h2>'. t('Azaran Mehr Group Latest News - !nid', array('!nid' => $object->nid)) .'</h2><br/>Test';

      drupal_mail('beep', 'reply', $row->mail, language_default(),
              array('body' => $message, 'subject' => $subject), $default_from, TRUE);
    }
  }
}

function _vdump($var, $keys = FALSE) {
  if($keys){
    drupal_set_message('<pre>' . print_r(array_keys($var), 1) . '</pre>');
  }
  else {
    drupal_set_message('<pre>' . print_r($var, 1) . '</pre>');
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜