У меня уже есть контроллер, модели и представление для галереи страниц бэкэнда и внешнего интерфейса.Но каким-то образом моя внешняя галерея не может подключиться, в то время как моя внутренняя часть уже может подключаться к базе данных и функционировать как 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.*"));
}
}
}
Вид: спереди: галерея.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) ?>" alt="" />
</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>