Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compact(): Undefined variable #14

Closed
sunshidan opened this issue Aug 23, 2019 · 2 comments
Closed

compact(): Undefined variable #14

sunshidan opened this issue Aug 23, 2019 · 2 comments

Comments

@sunshidan
Copy link

"compact(): Undefined variable: source"
在/modules/Translator/start.php 这个文件报这个错
\Form::macro('translate', function($attrs) {
$value = $this->getValue($attrs);
$id = $this->getId($attrs);
$name = $this->getAttribute($attrs, 'name');
$button = $this->getAttribute($attrs, 'button', trans('translator::translator.button'));

$options = [
    'url'       => $this->getAttribute($attrs, 'url',  route('translator.translate')),
    'source'    => $this->getAttribute($attrs, 'source',  ''),
    'format'    => $this->getAttribute($attrs, 'format', ''),
    'from'      => $this->getAttribute($attrs, 'from', ''),
    'to'        => $this->getAttribute($attrs, 'to', ''),
    'maxlength' => $this->getAttribute($attrs, 'maxlength', '', false),
    'separator' => $this->getAttribute($attrs, 'separator', ''),
];

return $this->toHtmlString(
    $this->view->make('translator::field.translate')->with(compact('name', 'id', 'value', 'attrs', 'source', 'button', 'options'))->render()//这句话报错 提示找不到source变量
);

});

解决方法定义一个$source='';变量即可 我的php环境时php7.3.6

@zotopteam
Copy link
Owner

zotopteam commented Aug 23, 2019

看到了,这里应该是有错误,我检查一下为什么我这里没报错

@zotopteam
Copy link
Owner

zotopteam commented Aug 23, 2019

解决方案:去掉compact中的source

$this->view->make('translator::field.translate')->with(compact('name', 'id', 'value', 'attrs', 'source', 'button', 'options'))->render()

改为

$this->view->make('translator::field.translate')->with(compact('name', 'id', 'value', 'attrs', 'button', 'options'))->render()

直接传递source是之前版本的做法,后面版本已经改成了通过options 传递,这里忘记修改了,因为我这里先前测试中一直都没报错所以并未发现,感谢反馈,后续版本将修正

zotopteam added a commit that referenced this issue Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants