提问人:Sony Haryono 提问时间:11/7/2023 最后编辑:Sony Haryono 更新时间:11/8/2023 访问量:58
无法访问字符串 Codeigniter 4 上字符串类型的偏移量
Cannot access offset of type string on string Codeigniter 4
问:
我收到此错误:
无法访问字符串上字符串类型的偏移量
尝试使用foreach()
在这一行:
<li><a href="javascript:void(0);"><?= $tags['tag_berita'] ?></a></li>
错误日志:
CRITICAL - 2023-11-08 15:42:50 --> Cannot access offset of type string on string
in APPPATH\Views\front\detail_berita.php on line 253.
1 SYSTEMPATH\View\View.php(226): include()
2 SYSTEMPATH\View\View.php(229): CodeIgniter\View\View->CodeIgniter\View\{closure}()
3 SYSTEMPATH\Common.php(1178): CodeIgniter\View\View->render('front/detail_berita', [], true)
4 APPPATH\Controllers\Berita.php(73): view('front/detail_berita', [...])
5 SYSTEMPATH\CodeIgniter.php(915): App\Controllers\Berita->detailBerita('wali-kota-bersama-kajari-pekalongan-teken-mou-bidang-perdata-dan-tun')
6 SYSTEMPATH\CodeIgniter.php(492): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Berita))
7 SYSTEMPATH\CodeIgniter.php(353): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
8 FCPATH\index.php(79): CodeIgniter\CodeIgniter->run()
9 SYSTEMPATH\Commands\Server\rewrite.php(47): require_once('C:\\xampp\\htdocs\\admin\\public\\index.php')
detail_berita.php:
<div class="sidebar-item mb-4">
<h4 class="">All Categories</h4>
<ul class="sidebar-category">
<li class="border-danger-subtle"><a class="stretched-link" href="javascript:void(0);">All</a></li>
<?php foreach ($ktg as $ktgs) : ?>
<li class="border-danger-subtle"><a class="stretched-link" href="javascript:void(0);"><?= $ktgs['kategori'] ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div class="sidebar-item mb-4">
<h4 class="">Tags</h4>
<ul class="sidebar-tags">
<?php foreach ($tag as $tags) : ?>
<li><a href="javascript:void(0);"><?= $tags['tag_berita'] ?></a></li>
<?php endforeach; ?>
</ul>
</div>
控制器:
public function detailBerita($slug_berita)
{
$data = [
'judul' => 'Detail Berita'
];
$data['beritaid'] = $this->b->select('*')
->select('tb_berita.updated_at as tgl_berita')
->join('tb_kategori', 'id_kategori = kategori_id', 'left')
->join('users', 'tb_berita.username = users.username', 'left')
->join('tb_user', 'tb_user.user_id = users.id', 'left')
->where('slug_berita', $slug_berita, 'after')
->find();
$data['tag'] = $this->b->select('tag_berita')->findAll();
$data['ktg'] = $this->k->select('*')->orderBy('kategori asc')->findAll();
// dd($data);
return view('front/detail_berita', $data);
}
我想像对类别一样循环标签数据,类别可以正常显示,但是当我添加标签数据时出现错误
答: 暂无答案
评论
$tags
writable/logs/log-2023-11-07.log