SAE_2.02/CodeIgniter-3.1.13/application/controllers/Search.php

69 lines
2.5 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Search extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Search_model');
$this->load->helper('url');
$this->load->helper('html');
}
public function index(){
// Récupérer la requête de recherche depuis la barre de recherche
$query = $this->input->get('query');
include 'temporaire.php';
// Vérifier que la requête de recherche n'est pas vide
if (empty($query)) {
// Charger la vue avec un message d'erreur
$data['query'] = $query;
$data['musiques'] = [];
$data['albums'] = [];
$data['genres'] = [];
$data['artistes'] = [];
$data['error'] = "La requête de recherche ne peut pas être vide.";
if($logged == true){
$this->load->view('layout/header_dark');
$this->load->view('layout/header_logged_dark');
$this->load->view('search_results', $data);
$this->load->view('layout/footer_dark');
} else {
$this->load->view('layout/header_dark');
$this->load->view('layout/header_not_logged_dark');
$this->load->view('search_results', $data);
$this->load->view('layout/footer_dark');
}
return;
}
// Faire une recherche dans les musiques, les albums, les genres et les artistes
$musiques = $this->Search_model->searchMusiques($query);
$albums = $this->Search_model->searchAlbums($query);
$genres = $this->Search_model->searchGenres($query);
$artistes = $this->Search_model->searchArtistes($query);
// Charger la vue avec les résultats de la recherche
$data['query'] = $query;
$data['musiques'] = $musiques;
$data['albums'] = $albums;
$data['genres'] = $genres;
$data['artistes'] = $artistes;
if($logged == true){
$this->load->view('layout/header_dark');
$this->load->view('layout/header_logged_dark');
$this->load->view('search_results', $data);
$this->load->view('layout/footer_dark');
} else {
$this->load->view('layout/header_dark');
$this->load->view('layout/header_not_logged_dark');
$this->load->view('search_results', $data);
$this->load->view('layout/footer_dark');
}
}
}