提问人:uul 提问时间:8/19/2023 最后编辑:Olivieruul 更新时间:9/16/2023 访问量:555
如何解决在Codeigniter 4中布局视图时警告“在全局代码中使用$this可能是未添加的PHP(PHP0437)”?
How to solve warning 'Use of $this in global code might be unatendedPHP(PHP0437)' when layouting view in Codeigniter 4?
问:
我仍然是codeigniter的初学者。我尝试在 codeigniter 4 中使用视图布局来布局模板(dinamic 页面)。但是所有的代码
$this
有警告说
在全局代码中使用 $this 可能是未使用的PHP(PHP0437)
仍在运行的网络导致它只是黄色警告,而不是红色警告。但是谁能用这个警告来解释我以及如何解决它?非常感谢您的回复。
这是我的模板代码,名为“默认.php”:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" name="viewport">
<!-- <title>Amalia House of Muslimah — HOM</title> -->
<?= $this->renderSection('title') ?>
<!-- General CSS Files -->
<link rel="stylesheet" href="assets/modules/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/modules/fontawesome/css/all.min.css">
<!-- CSS Libraries -->
<!-- Template CSS -->
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/components.css">
<!-- Start GA -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-94034622-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-94034622-3');
</script>
<!-- /END GA -->
</head>
<body>
<div id="app">
<div class="main-wrapper main-wrapper-1">
<div class="navbar-bg"></div>
<nav class="navbar navbar-expand-lg main-navbar">
<form class="form-inline mr-auto">
<ul class="navbar-nav mr-3">
<li><a href="#" data-toggle="sidebar" class="nav-link nav-link-lg"><i
class="fas fa-bars"></i></a></li>
<li><a href="#" data-toggle="search" class="nav-link nav-link-lg d-sm-none"><i
class="fas fa-search"></i></a></li>
</ul>
<!-- SEARCH START -->
<div class="search-element">
<input class="form-control" type="search" placeholder="Search" aria-label="Search"
data-width="250">
<button class="btn" type="submit"><i class="fas fa-search"></i></button>
<div class="search-backdrop"></div>
<div class="search-result">
<div class="search-header">
Histories
</div>
<div class="search-item">
<a href="#">How to hack NASA using CSS</a>
<a href="#" class="search-close"><i class="fas fa-times"></i></a>
</div>
<div class="search-item">
<a href="#">Kodinger.com</a>
<a href="#" class="search-close"><i class="fas fa-times"></i></a>
</div>
<div class="search-item">
<a href="#">#Stisla</a>
<a href="#" class="search-close"><i class="fas fa-times"></i></a>
</div>
<div class="search-header">
Result
</div>
<div class="search-item">
<a href="#">
<img class="mr-3 rounded" width="30" src="assets/img/products/product-3-50.png"
alt="product">
oPhone S9 Limited Edition
</a>
</div>
<div class="search-item">
<a href="#">
<img class="mr-3 rounded" width="30" src="assets/img/products/product-2-50.png"
alt="product">
Drone X2 New Gen-7
</a>
</div>
<div class="search-item">
<a href="#">
<img class="mr-3 rounded" width="30" src="assets/img/products/product-1-50.png"
alt="product">
Headphone Blitz
</a>
</div>
<div class="search-header">
Projects
</div>
<div class="search-item">
<a href="#">
<div class="search-icon bg-danger text-white mr-3">
<i class="fas fa-code"></i>
</div>
Stisla Admin Template
</a>
</div>
<div class="search-item">
<a href="#">
<div class="search-icon bg-primary text-white mr-3">
<i class="fas fa-laptop"></i>
</div>
Create a new Homepage Design
</a>
</div>
</div>
</div>
<!-- SEARCH END -->
</form>
<ul class="navbar-nav navbar-right">
<!-- MESSAGES START -->
<li class="dropdown dropdown-list-toggle"><a href="#" data-toggle="dropdown"
class="nav-link nav-link-lg message-toggle beep"><i class="far fa-envelope"></i></a>
<div class="dropdown-menu dropdown-list dropdown-menu-right">
<div class="dropdown-header">Messages
<div class="float-right">
<a href="#">Mark All As Read</a>
</div>
</div>
<div class="dropdown-list-content dropdown-list-message">
<a href="#" class="dropdown-item dropdown-item-unread">
<div class="dropdown-item-avatar">
<img alt="image" src="assets/img/avatar/avatar-1.png" class="rounded-circle">
<div class="is-online"></div>
</div>
<div class="dropdown-item-desc">
<b>Kusnaedi</b>
<p>Hello, Bro!</p>
<div class="time">10 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item dropdown-item-unread">
<div class="dropdown-item-avatar">
<img alt="image" src="assets/img/avatar/avatar-2.png" class="rounded-circle">
</div>
<div class="dropdown-item-desc">
<b>Dedik Sugiharto</b>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
<div class="time">12 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item dropdown-item-unread">
<div class="dropdown-item-avatar">
<img alt="image" src="assets/img/avatar/avatar-3.png" class="rounded-circle">
<div class="is-online"></div>
</div>
<div class="dropdown-item-desc">
<b>Agung Ardiansyah</b>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<div class="time">12 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item">
<div class="dropdown-item-avatar">
<img alt="image" src="assets/img/avatar/avatar-4.png" class="rounded-circle">
</div>
<div class="dropdown-item-desc">
<b>Ardian Rahardiansyah</b>
<p>Duis aute irure dolor in reprehenderit in voluptate velit ess</p>
<div class="time">16 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item">
<div class="dropdown-item-avatar">
<img alt="image" src="assets/img/avatar/avatar-5.png" class="rounded-circle">
</div>
<div class="dropdown-item-desc">
<b>Alfa Zulkarnain</b>
<p>Exercitation ullamco laboris nisi ut aliquip ex ea commodo</p>
<div class="time">Yesterday</div>
</div>
</a>
</div>
<div class="dropdown-footer text-center">
<a href="#">View All <i class="fas fa-chevron-right"></i></a>
</div>
</div>
</li>
<!-- MESSAGES END -->
<!-- NOTIF START -->
<li class="dropdown dropdown-list-toggle"><a href="#" data-toggle="dropdown"
class="nav-link notification-toggle nav-link-lg beep"><i class="far fa-bell"></i></a>
<div class="dropdown-menu dropdown-list dropdown-menu-right">
<div class="dropdown-header">Notifications
<div class="float-right">
<a href="#">Mark All As Read</a>
</div>
</div>
<div class="dropdown-list-content dropdown-list-icons">
<a href="#" class="dropdown-item dropdown-item-unread">
<div class="dropdown-item-icon bg-primary text-white">
<i class="fas fa-code"></i>
</div>
<div class="dropdown-item-desc">
Template update is available now!
<div class="time text-primary">2 Min Ago</div>
</div>
</a>
<a href="#" class="dropdown-item">
<div class="dropdown-item-icon bg-info text-white">
<i class="far fa-user"></i>
</div>
<div class="dropdown-item-desc">
<b>You</b> and <b>Dedik Sugiharto</b> are now friends
<div class="time">10 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item">
<div class="dropdown-item-icon bg-success text-white">
<i class="fas fa-check"></i>
</div>
<div class="dropdown-item-desc">
<b>Kusnaedi</b> has moved task <b>Fix bug header</b> to <b>Done</b>
<div class="time">12 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item">
<div class="dropdown-item-icon bg-danger text-white">
<i class="fas fa-exclamation-triangle"></i>
</div>
<div class="dropdown-item-desc">
Low disk space. Let's clean it!
<div class="time">17 Hours Ago</div>
</div>
</a>
<a href="#" class="dropdown-item">
<div class="dropdown-item-icon bg-info text-white">
<i class="fas fa-bell"></i>
</div>
<div class="dropdown-item-desc">
Welcome to Stisla template!
<div class="time">Yesterday</div>
</div>
</a>
</div>
<div class="dropdown-footer text-center">
<a href="#">View All <i class="fas fa-chevron-right"></i></a>
</div>
</div>
</li>
<!-- NOTIF END -->
<!-- USER START -->
<li class="dropdown"><a href="#" data-toggle="dropdown"
class="nav-link dropdown-toggle nav-link-lg nav-link-user">
<img alt="image" src="assets/img/avatar/avatar-1.png" class="rounded-circle mr-1">
<div class="d-sm-none d-lg-inline-block">Hi, Amalia</div>
</a>
<div class="dropdown-menu dropdown-menu-right">
<div class="dropdown-title">Logged in 5 min ago</div>
<a href="features-profile.html" class="dropdown-item has-icon">
<i class="far fa-user"></i> Profile
</a>
<a href="features-activities.html" class="dropdown-item has-icon">
<i class="fas fa-bolt"></i> Activities
</a>
<a href="features-settings.html" class="dropdown-item has-icon">
<i class="fas fa-cog"></i> Settings
</a>
<div class="dropdown-divider"></div>
<a href="#" class="dropdown-item has-icon text-danger">
<i class="fas fa-sign-out-alt"></i> Logout
</a>
</div>
</li>
<!-- USER END -->
</ul>
</nav>
<div class="main-sidebar sidebar-style-2">
<aside id="sidebar-wrapper">
<div class="sidebar-brand row row-cols-1">
<div class="col">
<img src="/assets/img/logo/logo.png" style="width: 40px; height: 40px;">
</div>
<div class="col" style="line-height: 20px;">
<a href="<?=site_url()?>" class="col" style="color: #ff3d87;">A M A L I A</a><br>
<a href="<?=site_url()?>" class="col">House of Muslimah</a>
</div>
</div>
<!-- ??-->
<div class="sidebar-brand sidebar-brand-sm">
<a href="<?=site_url()?>">St</a>
</div>
<!-- ?? -->
<ul class="sidebar-menu">
<li class="<?= $menu == 'dashboard' ? 'active' : ''?>"><a class="nav-link"
href="<?=site_url()?>"><i class="fas fa-fire"></i>
<span>Dashboard</span></a></li>
<li class="dropdown <?= $menu == 'manage' ? 'active' : ''?>">
<a href="#" class="nav-link has-dropdown" data-toggle="dropdown"><i
class="fa fa-clipboard-list"></i> <span>Manage</span></a>
<ul class="dropdown-menu">
<li><a class="nav-link <?= $submenu == 'manageusers' ? 'active' : ''?>"
href="<?=site_url('manage_users')?>">Manage Users</a></li>
<li><a class="nav-link <?= $submenu == 'manageevents' ? 'active' : ''?>"
href="<?=site_url('manage_events')?>">Manage Events</a></li>
<li><a class="nav-link <?= $submenu == 'managesantriwati' ? 'active' : ''?>"
href="<?=site_url('manage_santriwati')?>">Manage Santriwati</a>
</li>
</ul>
</li>
<li class="<?= $menu == 'jamaah' ? 'active' : ''?>"><a class="nav-link"
href="<?=site_url('jamaah')?>"><i class="fa fa-mosque"></i>
<span>Jama'ah</span></a></li>
<li class="dropdown <?= $menu == 'laporansantriwati' ? 'active' : ''?>">
<a href="#" class="nav-link has-dropdown"><i class="fa fa-book"></i>
<span>Laporan Santriwati</span></a>
<ul class="dropdown-menu">
<li><a class="nav-link <?= $submenu == 'pelanggaran' ? 'active' : ''?>"
href="<?=site_url('pelanggaran')?>">Pelanggaran</a></li>
<li><a class="nav-link <?= $submenu == 'prestasi' ? 'active' : ''?>"
href="<?=site_url('prestasi')?>">Prestasi</a></li>
<li><a class="nav-link <?= $submenu == 'raportpenilaian' ? 'active' : ''?>"
href="<?=site_url('raport_penilaian')?>">Raport Penilaian</a>
</li>
</ul>
</li>
</ul>
<!-- BUTTON START -->
<!-- <div class="mt-4 mb-4 p-3 hide-sidebar-mini">
<a href="https://getstisla.com/docs" class="btn btn-primary btn-lg btn-block btn-icon-split">
<i class="fas fa-rocket"></i> Documentation
</a>
</div> -->
<!-- BUTTON END -->
</aside>
</div>
<!-- Main Content -->
<div class="main-content">
<?= $this->renderSection('content') ?>
</div>
<footer class="main-footer">
<div class="footer-left">
Copyright © 2023 <div class="bullet"></div> Design By <a
href="https://chalathadoa.github.io/">Udkhul Rogodan</a>
</div>
<div class="footer-right">
v1.0
</div>
</footer>
</div>
</div>
<!-- General JS Scripts -->
<script src="assets/modules/jquery.min.js"></script>
<script src="assets/modules/popper.js"></script>
<script src="assets/modules/tooltip.js"></script>
<script src="assets/modules/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/modules/nicescroll/jquery.nicescroll.min.js"></script>
<script src="assets/modules/moment.min.js"></script>
<script src="assets/js/stisla.js"></script>
<!-- JS Libraies -->
<!-- Page Specific JS File -->
<!-- Template JS File -->
<script src="assets/js/scripts.js"></script>
<script src="assets/js/custom.js"></script>
</body>
</html>
这是我的视图主页,名为“ViewHome.php”
<?= $this->extend('layout/default') ?>
<?= $this->section('title') ?>
<title>Home | Amalia House of Muslimah</title>
<?= $this->endSection() ?>
<?= $this->section('content') ?>
<section class="section">
<div class="section-header">
<h1>Dashboard</h1>
</div>
<div class="section-body">
</div>
</section>
<?= $this->endSection() ?>
在我观看的教程中,似乎没有问题
Sthis
法典。这是我看过的教程。文本。非常感谢您的回复。
答:
0赞
Simon Weber
8/21/2023
#1
此警告似乎是由特定的代码分析器生成的。
要告诉你的分析器/linter/what在这种情况下什么都可以,请在你的视图文件前面添加一个文档块:$this
<?php
/**
* @var CodeIgniter\View\View $this
*/
?>
评论
0赞
Simon Weber
8/29/2023
很高兴我能帮:)考虑将我的答案标记为已接受的答案。
0赞
Muhammad Ridho Saputra
9/16/2023
#2
在setting.json上输入以下内容:
"php.problems.exclude": {
"/": [437],
"vendor/": true
}
评论