0 關注者

類別 yii\web\JsExpression

繼承關係yii\web\JsExpression » yii\base\BaseObject
實作介面yii\base\Configurable
自版本起可用2.0
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/web/JsExpression.php

JsExpression 將字串標記為 JavaScript 表達式。

當使用 yii\helpers\Json::encode()yii\helpers\Json::htmlEncode() 編碼一個值時,JsExpression 物件將被特殊處理,並編碼為 JavaScript 表達式而不是字串。

公共屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$expression 字串 此物件表示的 JavaScript 表達式 yii\web\JsExpression

公共方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫未定義為類別方法的具名方法。 yii\base\BaseObject
__construct() 建構子。 yii\web\JsExpression
__get() 回傳物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,亦即已定義且非 null。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__toString() 將物件轉換為字串的 PHP 魔術方法。 yii\web\JsExpression
__unset() 將物件屬性設定為 null。 yii\base\BaseObject
canGetProperty() 回傳一個值,指示屬性是否可讀取。 yii\base\BaseObject
canSetProperty() 回傳一個值,指示屬性是否可設定。 yii\base\BaseObject
className() 回傳此類別的完整限定名稱。 yii\base\BaseObject
hasMethod() 回傳一個值,指示是否已定義方法。 yii\base\BaseObject
hasProperty() 回傳一個值,指示是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\base\BaseObject

屬性詳情

隱藏繼承的屬性

$expression 公共屬性

此物件表示的 JavaScript 表達式

public string $expression null

方法詳情

隱藏繼承的方法

__call() 公共方法

定義於: yii\base\BaseObject::__call()

呼叫未定義為類別方法的具名方法。

請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當調用未知方法時,它會被隱式呼叫。

public mixed __call ( $name, $params )
$name 字串

方法名稱

$params array

方法參數

return mixed

方法回傳值

throws yii\base\UnknownMethodException

當呼叫未知方法時

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() public method

建構子。

public void __construct ( $expression, $config = [] )
$expression 字串

此物件表示的 JavaScript 表達式

$config array

此物件的額外配置

                public function __construct($expression, $config = [])
{
    $this->expression = $expression;
    parent::__construct($config);
}

            
__get() public method

定義於: yii\base\BaseObject::__get()

回傳物件屬性的值。

請勿直接呼叫此方法,因為它是 PHP 的魔術方法,將在執行 $value = $object->property; 時隱式呼叫。

另請參閱 __set()

public mixed __get ( $name )
$name 字串

屬性名稱

return mixed

屬性值

throws yii\base\UnknownPropertyException

如果屬性未定義

throws yii\base\InvalidCallException

如果屬性為唯寫

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public method

定義於: yii\base\BaseObject::__isset()

檢查屬性是否已設定,亦即已定義且非 null。

請勿直接呼叫此方法,因為它是 PHP 的魔術方法,將在執行 isset($object->property) 時隱式呼叫。

請注意,如果屬性未定義,將會回傳 false。

另請參閱 https://php.dev.org.tw/manual/en/function.isset.php

public boolean __isset ( $name )
$name 字串

屬性名稱或事件名稱

return boolean

指定的屬性是否已設定(非 null)。

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() public method

定義於: yii\base\BaseObject::__set()

設定物件屬性的值。

請勿直接呼叫此方法,因為它是 PHP 的魔術方法,將在執行 $object->property = $value; 時隱式呼叫。

另請參閱 __get()

public void __set ( $name, $value )
$name 字串

屬性名稱或事件名稱

$value mixed

屬性值

throws yii\base\UnknownPropertyException

如果屬性未定義

throws yii\base\InvalidCallException

如果屬性為唯讀

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            
__toString() public method

將物件轉換為字串的 PHP 魔術方法。

public string __toString ( )
return 字串

JavaScript 表達式。

                public function __toString()
{
    return (string) $this->expression;
}

            
__unset() public method

定義於: yii\base\BaseObject::__unset()

將物件屬性設定為 null。

請勿直接呼叫此方法,因為它是 PHP 的魔術方法,將在執行 unset($object->property) 時隱式呼叫。

請注意,如果屬性未定義,此方法將不會執行任何操作。如果屬性為唯讀,它將拋出例外。

另請參閱 https://php.dev.org.tw/manual/en/function.unset.php

public void __unset ( $name )
$name 字串

屬性名稱

throws yii\base\InvalidCallException

如果屬性為唯讀。

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            
canGetProperty() public method

定義於: yii\base\BaseObject::canGetProperty()

回傳一個值,指示屬性是否可讀取。

如果符合以下條件,屬性即為可讀:

  • 類別具有與指定名稱相關聯的 getter 方法(在此情況下,屬性名稱不區分大小寫);
  • 類別具有具有指定名稱的成員變數(當 $checkVars 為 true 時);

另請參閱 canSetProperty()

public boolean canGetProperty ( $name, $checkVars true )
$name 字串

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否可讀

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() public method

定義於: yii\base\BaseObject::canSetProperty()

回傳一個值,指示屬性是否可設定。

如果符合以下條件,屬性即為可寫:

  • 類別具有與指定名稱相關聯的 setter 方法(在此情況下,屬性名稱不區分大小寫);
  • 類別具有具有指定名稱的成員變數(當 $checkVars 為 true 時);

另請參閱 canGetProperty()

public boolean canSetProperty ( $name, $checkVars true )
$name 字串

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否可寫

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
className() public static method
自 2.0.14 版本起已棄用。在 PHP >= 5.5 版本上,請改用 ::class

定義於: yii\base\BaseObject::className()

回傳此類別的完整限定名稱。

public static string className ( )
return 字串

此類別的完整限定名稱。

                public static function className()
{
    return get_called_class();
}

            
hasMethod() public method

定義於: yii\base\BaseObject::hasMethod()

回傳一個值,指示是否已定義方法。

預設實作是呼叫 PHP 函數 method_exists()。當您實作 PHP 魔術方法 __call() 時,您可以覆寫此方法。

public boolean hasMethod ( $name )
$name 字串

方法名稱

return boolean

方法是否已定義

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() public method

定義於: yii\base\BaseObject::hasProperty()

回傳一個值,指示是否已定義屬性。

如果符合以下條件,屬性即為已定義:

  • 類別具有與指定名稱相關聯的 getter 或 setter 方法(在此情況下,屬性名稱不區分大小寫);
  • 類別具有具有指定名稱的成員變數(當 $checkVars 為 true 時);

另請參閱

public boolean hasProperty ( $name, $checkVars true )
$name 字串

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

return boolean

屬性是否已定義

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
init() public method

定義於: yii\base\BaseObject::init()

初始化物件。

此方法在建構子結束時呼叫,在物件使用給定的配置初始化之後。

public void init ( )

                public function init()
{
}