gpt4 book ai didi

php - CodeIgniter - Hello World

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:00:17 24 4
gpt4 key购买 nike

我是 PHP 和 CodeIgniter 的新手,目前正在研究两者的教程。我正在尝试构建博客教程,但收到一些错误。帮助将不胜感激。提前致谢!

Controller :

<?php

class Blog extends Controller{
function index()
{
$data['title'] = "My Blog Title";
$data['heading'] = "My Blog Heading";
$data['todo'] = array('clean house','eat lunch','call mom');

$this->load->view('blog_view');
}
}
?>

查看:

<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1><?=$heading?></h1>

<ol>

<?php foreach($todo as $item): ?>

<li><?=$item?></li>

<?php endforeach; ?>
</ol>

</body>
</html>

错误:

Message: Undefined variable: heading
Filename: views/blog_view.php
Line Number: 6


Message: Undefined variable: todo
Filename: views/blog_view.php
Line Number: 10


Message: Invalid argument supplied for foreach()
Filename: views/blog_view.php
Line Number: 10

最佳答案

您需要将 $data 变量传递给 View :

$this->load->view('blog_view', $data);

关于php - CodeIgniter - Hello World ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/699396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com