Laravel template page variable is undefined?
天蓬老师
天蓬老师 2017-05-31 10:31:47
0
3
982

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.

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
淡淡烟草味
<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>
给我你的怀抱

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

Ty80

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?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!