如何制作前端 Gallery.view 代码点火器
Posted
技术标签:
【中文标题】如何制作前端 Gallery.view 代码点火器【英文标题】:How to make frontend Gallery.view codeigniter 【发布时间】:2018-10-09 05:34:26 【问题描述】:我已经拥有后端和前端页面库的控制器、模型和视图。但不知何故,我的前端库无法连接,同时,我的后端已经可以连接到数据库并像 crud 一样运行。我不知道我哪里出错了,谁能帮帮我?
控制器:galleryweb.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Galleryweb extends CI_Controller
public function __construct()
parent::__construct();
$this->load->model("galleryweb_model");
$this->load->library('form_validation');
public function index()
$data["gallery"] = $this->galleryweb_model->getAll();
$this->load->view("front/gallery", $data);
模型:Galleryweb_model.php
class Galleryweb_model extends CI_Model
function __construct()
parent::__construct();
private $_table = "gallery";
public $id_gallery;
public $name;
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_gallery" => $id])->row();
public function save()
$post = $this->input->post();
$this->id_gallery = uniqid();
$this->name = $post["name"];
$this->image = $this->_uploadImage();
$this->db->insert($this->_table, $this);
public function update()
$post = $this->input->post();
$this->id_gallery = $post["id"];
$this->name = $post["name"];
if (!empty($_FILES["image"]["name"]))
$this->image = $this->_uploadImage();
else
$this->image = $post["old_image"];
$this->db->update($this->_table, $this, array('id_gallery' => $post['id']));
public function delete($id)
$this->_deleteImage($id);
return $this->db->delete($this->_table, array("id_gallery" => $id));
private function _uploadImage()
$config['upload_path'] = './upload/galery/';
$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)
$gallery = $this->getById($id);
if ($gallery->image != "default.jpg")
$filename = explode(".", $gallery->image)[0];
return array_map('unlink', glob(FCPATH."upload/galery/$filename.*"));
查看:前面:gallery.php
<div class="container-fluid">
<div class="col-md-4 thumb">
<?php foreach ($gallery as $gallery): ?>
<a class="fancybox" href="<?php echo $gallery->name ?>" data-fancybox-group="gallery">
<img class="img-polaroid" src="<?php echo base_url('upload/galery/'.$gallery->image) ?>" />
</a>
<?php?>
</div>
<nav aria-label="Page navigation example ">
<center>
<ul class="pagination align-center">
<li class="page-item">
<a class="page-link" href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</center>
</nav>
</div>
【问题讨论】:
您的问题过于宽泛且不具体。你到底有什么问题?您只是在问如何将数据从控制器传递到视图吗?然后你应该阅读 CI 的文档。如果这不是您要问的,那么您需要澄清您的问题。 我没听懂你想说什么。你在找 $this->load->view('name'); 【参考方案1】:$this->load->model("gallery_model");
但型号名称是 Galleryweb_model?
【讨论】:
我已经把它改成了galleryweb_model,但它仍然出现这样的错误:遇到未捕获的异常类型:ParseError 消息:语法错误,文件意外结束文件名:C:\xampp\htdocs\eat\application \views\front\gallery.php 行号:261 回溯:文件:C:\xampp\htdocs\eat\application\controllers\galleryweb.php 行:16 功能:查看文件:C:\xampp\htdocs\eat\index .php 行:315 功能:require_once以上是关于如何制作前端 Gallery.view 代码点火器的主要内容,如果未能解决你的问题,请参考以下文章