我不知道该怎么办,我的索引页不起作用...我的意思是说它在添加已经连接到数据库的功能滑块之前工作正常...我该怎么办?
遇到未捕获的异常
类型:ParseError
消息:语法错误,意外的“ endforeach”(T_ENDFOREACH), 预计文件结束
文件名:C:\ xampp \ htdocs \ eat \ application \ views \ front \ index.php
行号:96
回溯:
文件:C:\ xampp \ htdocs \ eat \ application \ controllers \ index.php行:15 功能:查看
文件:C:\ xampp \ htdocs \ eat \ index.php行:315功能:require_once
视图:index.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; ?>
控制器:index.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);
}
}
模型:Indexweb_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.*"));
}
}
}
答案 0 :(得分:0)
500错误不是特定的错误,通常应指导您检查PHP日志文件以获取更多信息。确保已启用日志记录,并且在 RequestQueue queue = Volley.newRequestQueue(getContext());
StringRequest postRequest = new StringRequest(Request.Method.POST, url1,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(mBaseAppCompatActivity, "Success", Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
String token = getToken();
params.put("Authorization", "Bearer " + token);
params.put("Content-Type", "multipart/form-data");
return params;
}
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("terms", "true");
params.put("phone", "phoneNo");
return params;
}
};
queue.add(postRequest);
文件中指定了文件。您可能要同时检查那里和您的网络服务器日志。
答案 1 :(得分:0)
您的语法错误。
您错过了一个冒号,而您的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>