1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Datawriter: 'Gets the actual existing.....' - What does it actually mean?

Discussion in 'XenForo Development Discussions' started by TheBigK, Apr 14, 2015.

  1. TheBigK

    TheBigK Well-Known Member

    So far, I've been blindly following the DataWriter creation for my simpler addons; but have decided to figure out what's really happening behind the scenes. I see this explanation (comment)
    /*** Gets the actual existing data out of data that was passed in. See parent for explanation.** @param mixed** @return array|false*/protected function _getExistingData($data)
    if (!$id = $this->_getExistingPrimaryKey($data, 'note_id'))
    return false;}
    return array('scratchpad_note' => $this->getModelFromCache('Scratchpad_Model_Note')->getNoteById($id));}
    The words "gets the actual existing data out of data that was passed in" confuse me.

    1. Where is this $data coming from? What does it contain when being passed on to the function?
    2. Why is it mandatory to define this function in any data writer?
  2. xfrocks

    xfrocks Well-Known Member

    The callee may use something like this

    $dw XenForo_DataWriter::create('Something');
    That is the $data that is being used in the quoted lines. It can be an array or an ID. The method "_getExistingPrimaryKey" will extract "note_id" if $data is an array and has that key. Or it will just return $data if it is a number itself.

Share This Page