Editable::getSelector PHP Method

getSelector() public method

public getSelector ( )
    public function getSelector()
    {
        //for live updates selector should not contain pk
        if ($this->liveTarget) {
            return $this->name;
        }
        $pk = $this->pk;
        if ($pk === null) {
            $pk = 'new';
        } else {
            //support of composite keys: convert to string: e.g. 'id-1_lang-ru'
            if (is_array($pk)) {
                //below not works in PHP < 5.3, see https://github.com/vitalets/x-editable-yii/issues/39
                //$pk = join('_', array_map(function($k, $v) { return $k.'-'.$v; }, array_keys($pk), $pk));
                $buffer = array();
                foreach ($pk as $k => $v) {
                    $buffer[] = $k . '-' . $v;
                }
                $pk = join('_', $buffer);
            }
        }
        return $this->name . '_' . $pk;
    }

Usage Example

 public function getSelector()
 {
     return str_replace('\\', '_', get_class($this->staticModel)) . '_' . parent::getSelector();
 }