2015-04-08 2 views
0

У меня есть представление, которое содержит форму. URL-адрес формы - это адрес представления, в котором находится форма. в контроллере я передаю переменную виду, когда пользователь нажал кнопку в форме. , но мой взгляд имеет ошибку, говорит, что переменная i, переданная ей, не определена.не может получить доступ к переменной, переданной от контроллера, к моему представлению в laravel 4.2

вот мой код

мой взгляд:

@extends('layouts.master') 

@section('content') 

<?php 
    $category = Category::lists('name','name'); 
    $priority = Priority::lists('name','name'); 
    $lesson = Lesson::lists('name','name'); 
    $count = 1; 
?> 

{{ Form::open(array('action' => '[email protected]', 'method' => 'POST', 'id' => 'search_question')) }} 

    <div> 
     {{ Form::label('quiz_cat', 'نام دسته بندی') }} 
     {{ Form::select('quiz_cat', array('/'=>'انتخاب کنید')+$category, null, ['id' => 'cat_select']) }} 
    </div> 

    <div> 
     {{ Form::label('quiz_less','نام درس') }} 
     {{ Form::select('quiz_less',$lesson, null, ['id' => 'les_select']) }} 
    </div> 

    <div> 
     {{ Form::label('quiz_prio','سطح سوال') }} 
     {{ Form::select('quiz_prio',array('/'=>'انتخاب کنید')+$priority, null, ['id' => 'prio_select']) }} 
    </div> 

    <div> 
     {{Form::label('date_start','تاریخ شروع')}} 
     {{Form::input('date','date_start',null,array('id' => 'date_start'))}} 
    </div> 

    <div class='form-group'> 
     {{ Form::submit('جستجو', ['class' => 'btn btn-primary']) }} 
    </div> 

{{ Form::close() }} 

<iframe width="690px" height="300px" scrolling="yes"> 
{{ Form::open(array('method' => 'POST', 'id' => 'add_question')) }} 

<div class="col-lg-10 col-lg-offset-1"> 
    <div class="table-responsive" id="question_table"> 
     <table class="table table-bordered table-striped"> 
      <thead> 
      <tr> 
       <th>ردیف</th> 
       <th>عنوان سوال</th> 
       <th></th> 
      </tr> 
      </thead> 

      <tbody> 
      @foreach ($res as $quiz) 
       <tr> 
        <td align="center" width="100px"> 
         <?php echo $count++; ?> 
        </td> 
        <td align="center" width="200px">{{ $quiz->title }}</td> 
        <td align="center" width="200px"><input type="checkbox" name="select_question[]" id="{{ $quiz->lesson_id }}" value="{{ $quiz->id }}"></td> 
       </tr> 
      @endforeach 
      </tbody> 
     </table> 
    </div> 
</div> 

{{ Form::submit('افزودن', ['class' => 'btn btn-primary']) }} 

{{ Form::close() }} 
</iframe> 

@stop 

мой контроллер:

<?php 
class createQuizController extends BaseController { 

public function find() 
{ 
    $prio = Input::get('quiz_prio'); 
    $res1 = DB::select("select id from priority pr where '$prio' = pr.name"); 
    $r1 = $res1[0]->id; 

    $cat = Input::get('quiz_cat'); 
    $res2 = DB::select("select id from categories cat where '$cat' = cat.name"); 
    $r2 = $res2[0]->id; 

    $les = Input::get('quiz_less'); 
    $res3 = DB::select("select id from lesson less where '$les' = less.name"); 
    $r3 = $res3[0]->id; 

    $sdate = Input::get('date_start'); 

    $res = DB::select("select * from quiz where categories_id='$r2' and lesson_id='$r3' and priority_id='$r1' and date_start='$sdate'"); 

    return View::make('cquiz')->with('res',$res); 
} 

public function addQuestion() 
{ 
    $a = array(); 
    $a[] = Input::get('select_question'); 
    var_dump($a[]); 
     /*foreach($a as $b) { 
      $c = DB::select("select name from lesson where '$b'=id"); 
      var_dump($c); 
     }*/ 
} 

} 

мой маршрут:

Route::post('/cquiz/','[email protected]'); 
Route::post('/addQuestion/','[email protected]'); 
+0

какая переменная точно не определена? –

+0

Является ли эта переменная переменной $ res, которая не определена? может видеть, что вы только отправили одну переменную в представление здесь 'с ('res', $ res)' – Digitlimit

+0

$ res в клик-клинге –

ответ

0

попробовать это:

return View :: make ('cquiz') -> withRes ($ res);

и в представлении вы можете получить доступ к «$ res» (или {{$ res}} и т. Д.)

Смежные вопросы