【问题标题】:Dynamic Drop Down List using Laravel 5.2使用 Laravel 5.2 的动态下拉列表
【发布时间】:2016-08-04 16:17:50
【问题描述】:

我有数据库架构:

CREATE TABLE IF NOT EXISTS `zone` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `zone_name` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
);
INSERT INTO `zone` (`id`, `zone_name`) VALUES
(1, 'first'),
(2, 'second');

CREATE TABLE IF NOT EXISTS `error` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `errorID` int(11) NOT NULL,
  `error_name` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
);

INSERT INTO `error` (`id`, `errorID`, `error_name`) VALUES
(1, 1, 'test1'),
(2, 1, 'test2'),
(3, 1, 'test3'),
(4, 1, 'test4'),
(5, 2, 'test5');

MyController.php

class myController extends Controller {

    public function zoneMethod()
    {
        $zone = DB::table('zone')->get();

         return View::make('myview', ['zone' =>'zone']);

    }

    public function errorMethod($id)
    {
        $error = DB::table('error')->where('errorID', $id)->get();
        return View::make('thisview', ['error' => 'error']);
    }
}

Routes.php

Route::get('myroute','myController@zoneMethod');
Route::get('my/{id}','myController@errorMethod');

我有

查看.php

<label for="zones">Zone</label>
<select name="parent_zone" id="parent_zone">

    @foreach($zone as $zones)
    <option value="{{ $zones->id }}">{{ $zones->zone_name }}</option>
    @endforeach

</select>
<br/><br/>

<label for="errors">Error</label>
<select name="sub_error" id="sub_error">

        @foreach($error as $errors)
         <option value="{{ $errors->id }}">{{ $errors->error_name }}</option>
        @endforeach

<br/><br/>
</select>
</div> 

我有错误 - “未定义的变量:区域 ...”,请帮助我。

【问题讨论】:

    标签: php mysql laravel-5


    【解决方案1】:

    在控制器中编辑代码:

    return View::make('myview', ['zone' => $zone]);
    

    而不是

    return View::make('myview', ['zone' =>'zone']);
    

    【讨论】:

      猜你喜欢
      • 2016-08-25
      • 2018-05-15
      • 2016-07-10
      • 2020-04-13
      • 2016-07-01
      • 1970-01-01
      • 2016-07-12
      • 2020-06-29
      • 2017-03-06
      相关资源
      最近更新 更多