2019-04-30 10:22:05 1389次浏览 1条回答 0 悬赏 10 金钱
<?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>

像这种 $form->field($model, 'code') 返回值是一个对象 object(yii\widgets\ActiveField)
我也找不到 toString() 方法, 为什么都可以直接 echo

最佳答案

  • 花椒 发布于 2019-04-30 11:03 举报

    ActiveField有__toString()方法~
    /**

     * PHP magic method that returns the string representation of this object.
     * @return string the string representation of this object.
     */
    public function __toString()
    {
        // __toString cannot throw exception
        // use trigger_error to bypass this limitation
        try {
            return $this->render();
        } catch (\Exception $e) {
            ErrorHandler::convertExceptionToError($e);
            return '';
        }
    }
    
    public function render($content = null)
    {
        if ($content === null) {
            if (!isset($this->parts['{input}'])) {
                $this->textInput();
            }
            if (!isset($this->parts['{label}'])) {
                $this->label();
            }
            if (!isset($this->parts['{error}'])) {
                $this->error();
            }
            if (!isset($this->parts['{hint}'])) {
                $this->hint(null);
            }
            $content = strtr($this->template, $this->parts);
        } elseif (!is_string($content)) {
            $content = call_user_func($content, $this);
        }
    
        return $this->begin() . "\n" . $content . "\n" . $this->end();
    }
    
    1 条回复
    回复于 2019-05-05 10:28 回复

    可能我搜索的时候没留意大小写 -_-||

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
{乱⒎八糟ゃ
助理

{乱⒎八糟ゃ 广东佛山

注册时间:2019-04-28
最后登录:2021-01-27
在线时长:2小时3分
  • 粉丝0
  • 金钱105
  • 威望0
  • 积分125

热门问题