简体   繁体   English

在laravel视图中未定义的变量

[英]undefined variable in a laravel view

i am new in laravel, i have a dropdown list and i want to populate it with years from 'UserController' i dont want to write a long list of year, i just want years to be added on every year change. 我是laravel的新手,我有一个下拉列表,我想用'UserController'的年份填充它,我不想写很长的年份列表,我只想在每年的更改中添加年份。

in my controller 在我的控制器中

public function setYear(){
        $op="";
        for($i=2010;$i<date('Y')+1;$i++)
            {
                $op.="<option value=".$i.">".$i."</option></br>";
            }
         return View::make('admin.setYear')->with('options',$op);
    }

in my view 在我看来

<select  name="gender">
  <option>Select</option>
    {{$op}}
</select>

i get this Undefined variable: op (View 我得到这个Undefined variable: op (View

how can i do this? 我怎样才能做到这一点?

Your variable name is options , not $op . 您的变量名是options ,而不是$op

The name you pass in the with() the first parameter is what you use to access it in the view. with()第一个参数中传递的名称是您在视图中用来访问它的名称。

Switch {{$op}} to {{$options}} {{$op}}切换为{{$options}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM