<?php $this->view('includes/header'); ?> <div class="p-4 mx-auto shadow rounded" style="margin-top:100px;width:100%;max-width: 310px"> <h2 class="text-center">学校管理系统</h2> <h3 class="text-center">登录</h3> <img src="<?= ROOT?>/assets/images/logo.jpg" alt="" style="width:100px" class="d-block mx-auto"> <br> <input type="email" name="email" placeholder="邮箱" class="form-control"> <br> <input type="password" name="password" placeholder="密码" class="form-control"> <br> <button class="btn btn-primary">登录</button> </div> <?php $this->view('includes/footer'); ?>上述代码报了Fatal error: Uncaught Error: Using $this when not in object context in D:\xampp\htdocs\school\private\views\login.view.php:1 Stack trace: #0 {main} thrown in D:\xampp\htdocs\school\private\views\login.view.php on line 1这个错误,应该怎么解决?
时间: 2023-07-12 14:04:23 浏览: 48
这个错误提示是因为在非对象上下文中使用了 $this 变量。通常情况下,$this 变量只能在类方法中使用,而不能在全局作用域中使用。
根据代码,可能是在一个视图文件中使用了 $this 变量,但该文件不属于任何类。你需要检查该视图文件是否正确引用了所在类的对象,或者将其中使用 $this 变量的代码移动到类方法中。如果视图文件不属于任何类,你需要使用全局变量或者函数参数传递所需的值。
相关问题
<div class="flex justify-center"> <img class="w-[100px] h-[100px] rounded-lg" :src="'https://wpimg.wallstcn.com/57ed425a-c71e-4201-9428-68760c0537c4.jpg' + avatarPrefix"> <div class="ml-3"> <el-descriptions class="el-descriptions__body" size="small" :column="Number('1')" border> <el-descriptions-item label="电压">380 V</el-descriptions-item> <el-descriptions-item label="电流">10 A</el-descriptions-item> <el-descriptions-item label="通讯">正常 </el-descriptions-item> </el-descriptions> </div> </div> 实现电压电流通讯文字显示在图片右侧如何实现
可以使用Flex布局,将图片和文字包裹在一个父容器中,然后将父容器设置为Flex布局,让其中的子元素水平排列。具体代码如下:
```
<div class="flex justify-center">
<img class="w-[100px] h-[100px] rounded-lg" :src="'https://wpimg.wallstcn.com/57ed425a-c71e-4201-9428-68760c0537c4.jpg' + avatarPrefix">
<div class="ml-3 flex">
<el-descriptions class="el-descriptions__body" size="small" :column="Number('1')" border>
<el-descriptions-item label="电压">380 V</el-descriptions-item>
<el-descriptions-item label="电流">10 A</el-descriptions-item>
<el-descriptions-item label="通讯">正常 </el-descriptions-item>
</el-descriptions>
</div>
</div>
```
在上面的代码中,我们给第二个子元素的父容器添加了`flex`类,并且在样式中设置了`justify-content: space-between`,让其中的子元素在水平方向上均匀分布。同时,我们给第二个子元素添加了`ml-3`类,让其在水平方向上有一定的间距。这样就能够实现电压、电流、通讯文字显示在图片右侧的效果了。
<el-col :span="6" :xs="24"> <div class="card-list" style="display: flex;width: 100%;flex-wrap: wrap;justify-content: space-between; align-items: center;"> <!--div style="display: flex; justify-content: space-between; align-items: center;"--> <!--el-card style="margin-bottom:20px; width:300px;height:280px"--> <el-card style="width:300px;height:280px; margin-left:1px;margin-bottom: 10px"> <template #header> <div class="h-4 pl-[90px]" style="width: 100%;display: flex;justify-content: space-between; align-items: center;"> <div class="user-block" style="line-height: 30px;font-size: 20px;"> <span class="username text-muted" style="margin-left: 10px;">故障模拟设备</span> <span class="description" style="margin-left: 10px;">教学理论设备</span> </div> <el-tag class="username text-muted" style="margin-left: 10px;color:green">运行</el-tag> <div class="el-icon-setting" style="font-size: 25px; color: rgba(18, 21, 211, 0.829);" @click="update"></div> </div> </template> <div class="flex justify-center" style="display: flex;width: 100%;flex-wrap: wrap;justify-content: space-between; align-items: center;"> <img class="rightullidiv" :src="'../../../static/images/fan.gif'"> <!--img class="w-[100px] h-[100px] rounded-lg" src="'../../../static/images/fan.gif'" alt=""--> <div class="ml-3" style="width:120px;height:280px; margin-left:1px;margin-bottom: 10px"> <!--el-descriptions class="el-descriptions__body" size="small" :column="Number('1')" border--> <el-descriptions size="small" :column="Number('1')" border> <el-descriptions-item label="电压">380 V</el-descriptions-item> <el-descriptions-item label="电流">10 A</el-descriptions-item> <el-descriptions-item label="通讯">正常 </el-descriptions-item> </el-descriptions> </div> </div> </el-card> </div> </el-col>实现图片与el-descriptions-item label="电压"并排放置,如何修改代码
您可以将图片与el-descriptions-item label="电压"都放在一个div中,设置该div的display属性为flex,并设置justify-content为space-between或者space-around。具体代码如下:
```
<div class="flex justify-between">
<img class="rightullidiv" :src="'../../../static/images/fan.gif'">
<el-descriptions size="small" :column="Number('1')" border>
<el-descriptions-item label="电压">380 V</el-descriptions-item>
</el-descriptions>
</div>
```
您可以将以上代码替换掉原来的el-descriptions代码部分即可。