我不知道该怎么办,我的索引页不工作。。。我的意思是,在我添加已经连接到数据库的函数滑块之前,它工作得非常好。。。我该怎么办?
遇到未捕获的异常
类型:语法错误
消息:语法错误,意外的“endforeach”(T_endforeach),应为文件结尾
文件名:C:\xampp\htdocs\eat\application\views\front\index。php
电话号码:96
回溯:
File: C:\xampp\htdocs\ate\应用程序\控制器\index.phpLine: 15功能:view
文件:C:\xampp\htdocs\eat\index。php行:315函数:需要一次
视图:索引。php
<!--- Carousel -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php foreach ($slider as $slider) ?>
<div class="item-active">
<img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
<div class="carousel-caption">
<h3><?=$slider->name?></h3>
<p><?=$slider->description?></p>
</div>
</div>
<div class="item">
<img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
<div class="carousel-caption">
<h3><?=$slider->name?></h3>
<p><?=$slider->dekripsi?></p>
</div>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only"> previous</span>
</a>
<a class="right carousel-control" href="=#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only"> next </span>
</a>
</div>
<?php endforeach; ?>
控制器:索引。php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Index extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model("Indexweb_model");
$this->load->library('form_validation');
}
public function index()
{
$data["slider"] = $this->Indexweb_model->getAll();
$this->load->view("front/index", $data);
}
}
模特:我ndexweb_model.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Indexweb_model extends CI_Model
{
private $_table = "slider";
public $id_slider;
public $name;
public $deskripsi;
public $image;
public function rules()
{
return [
['field' => 'name',
'label' => 'Name',
'rules' => 'required']
];
}
public function getAll()
{
return $this->db->get($this->_table)->result();
}
public function getById($id)
{
return $this->db->get_where($this->_table, ["id_slider" => $id])->row();
}
public function save()
{
$post = $this->input->post();
// $this->id_slider = uniqid();
$this->name = $post["name"];
$this->deskripsi = $post["deskripsi"];
$this->image = $this->_uploadImage();
$this->db->insert($this->_table, $this);
}
public function update()
{
$post = $this->input->post();
$this->id_slider = $post["id"];
$this->name = $post["name"];
$this->deskripsi = $post["deskripsi"];
if (!empty($_FILES["image"]["name"])) {
$this->image = $this->_uploadImage();
} else {
$this->image = $post["old_image"];
}
$this->db->update($this->_table, $this, array('id_slider' => $post['id']));
}
public function delete($id)
{
$this->_deleteImage($id);
return $this->db->delete($this->_table, array("id_slider" => $id));
}
private function _uploadImage()
{
$config['upload_path'] = './upload/slider/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['upload_max_filesize'] = '100000M';
$config['post_max_size'] = '100000M';
$config['file_name'] = basename($_FILES["image"]["name"]);
$config['overwrite'] = true;
$this->load->library('upload', $config);
if ($this->upload->do_upload('image')) {
return $this->upload->data("file_name");
}
}
private function _deleteImage($id)
{
$slider = $this->getById($id);
if ($slider->image != "default.jpg") {
$filename = explode(".", $slider->image)[0];
return array_map('unlink', glob(FCPATH."upload/slider/$filename.*"));
}
}
}
这是正确的foreach结构,在您的代码中缺少“:”
<?php
foreach($array as $element):
#do something
endforeach;
?>
你的语法错了。您丢失了一个冒号,并且您的endForeach
位于错误的位置。
试试这个吧:
<!--- Carousel -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php foreach ($slider as $slider): ?>
<div class="item-active">
<img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
<div class="carousel-caption">
<h3><?=$slider->name?></h3>
<p><?=$slider->description?></p>
</div>
</div>
<div class="item">
<img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
<div class="carousel-caption">
<h3><?=$slider->name?></h3>
<p><?=$slider->dekripsi?></p>
</div>
</div>
<?php endforeach; ?>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only"> previous</span>
</a>
<a class="right carousel-control" href="=#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only"> next </span>
</a>
</div>
问题内容: 我有一个SQL查询,当将其放入函数中时,它将停止处理此错误消息。从功能中删除它会使它再次开始工作。 为什么是这样? 问题答案: 缩进的Heredoc分隔符将其破坏。说: 代替
问题内容: 我收到一个错误: 使用此代码: 有什么问题? 问题答案: 您应该避免这种情况(在代码末尾): 和这个: 您不应该将方括号直接放在open / close 标记附近,但要用空格隔开: 也避免和使用
问题内容: 编译后,我得到错误信息 为什么我不能将i ++放在切片索引中?切片索引有什么限制吗? 问题答案: 前往常见问题解答(FAQ) 为什么++和-语句而不是表达式?为什么使用后缀而不是前缀? 如果不使用指针算法,则前缀和后缀增量运算符的便利性值会下降。通过将它们从表达式层次结构中完全删除,可以简化表达式语法,并且可以消除围绕 和-(考虑f(i )和p [i] = q [++ i])的求值的混
我得到了的意外结束。代码对我来说很好,我错过了什么? 安慰:
PHP7.0。27(cli)(创建时间:2018年1月23日09:07:32)(NTS) 版权所有(c)1997-2017 PHP Group Zend Engine v3。0.0,版权所有(c)1998-2017 Zend Technologies 分析错误:语法错误,意外的T_类,应为T_字符串或T_变量或“$”在/path_to_项目/artisan在线31 X-Powered-By:PHP
我试图使用下面的代码从一个api网站获取一个JSON文件,但是当我使用下面的代码获取时,我得到一个错误,说“JSON输入意外结束”