search

Home  >  Q&A  >  body text

Laravel template page variable is undefined?

1. When the page accesses the blad template page, the variable is undefined.
2. Code

<p>
            <form method="POST" action="importexcel" enctype="multipart/form-data">
                <input type="file" name="myfile" /><br/>
                <input type="submit" name="submit" value="提交" />
            </form>
        </p>
        @if($flag_result == true)
            <p style="color:darkgreen;margin-top:5px;">
                导入数据成功
            </p>
        @endif

        @if(!($fileType == 'xlsx'))
            <p style="color:red;margin-top:5px;">
                数据不合法
            </p>
        @endif  
    </p>

3. It will prompt Undefined variable: flag_result
4. How to solve it?
PS: You can return view('importexcel',compact('flag_result','fileType')); in the control layer. I enter this view first. Then, submit the data into the controller and return to the page.

天蓬老师天蓬老师2764 days ago1035

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-31 10:33:47

    <p>
                <form method="POST" action="importexcel" enctype="multipart/form-data">
                    <input type="file" name="myfile" /><br/>
                    <input type="submit" name="submit" value="提交" />
                </form>
            </p>
           @if(isset($flag_result))
            @if($flag_result == true)
                <p style="color:darkgreen;margin-top:5px;">
                    导入数据成功
                </p>
            @endif
    
            @if(!($fileType == 'xlsx'))
                <p style="color:red;margin-top:5px;">
                    数据不合法
                </p>
            @endif  
           @endif
        </p>

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-31 10:33:47

    Then the question is, is $flag_result defined in the controller? Take a screenshot to see

    reply
    0
  • PHP中文网

    PHP中文网2017-05-31 10:33:47

    When you enter for the first time, you set it, and then when you submit the data and enter the controller, do you also set these two variables when you return to this view again?

    reply
    0
  • Cancelreply