diff --git a/CodeIgniter-3.1.13/application/controllers/Artiste.php b/CodeIgniter-3.1.13/application/controllers/Artiste.php index db8ac72..845f526 100644 --- a/CodeIgniter-3.1.13/application/controllers/Artiste.php +++ b/CodeIgniter-3.1.13/application/controllers/Artiste.php @@ -13,7 +13,7 @@ class Artiste extends CI_Controller { public function index($artiste_id){ // Récupérer les détails de l'artiste $artiste = $this->Model_artist->getArtisteById($artiste_id); - $mostUsedGenre = $this->Model_music->getMostUsedGenreByArtist($artiste_id); // Correction ici + $mostUsedGenre = $this->Model_music->getMostUsedGenreByArtist($artiste_id); if($artiste){ // Récupérer tous les albums de l'artiste diff --git a/CodeIgniter-3.1.13/application/controllers/Search.php b/CodeIgniter-3.1.13/application/controllers/Search.php index 122d87a..f43c682 100644 --- a/CodeIgniter-3.1.13/application/controllers/Search.php +++ b/CodeIgniter-3.1.13/application/controllers/Search.php @@ -13,6 +13,22 @@ class Search extends CI_Controller { // Récupérer la requête de recherche depuis la barre de recherche $query = $this->input->get('query'); + // 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."; + + $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); @@ -30,4 +46,4 @@ class Search extends CI_Controller { $this->load->view('search_results', $data); $this->load->view('layout/footer_dark'); } -} \ No newline at end of file +} diff --git a/CodeIgniter-3.1.13/application/models/Search_model.php b/CodeIgniter-3.1.13/application/models/Search_model.php index 7e8fb61..4b15113 100644 --- a/CodeIgniter-3.1.13/application/models/Search_model.php +++ b/CodeIgniter-3.1.13/application/models/Search_model.php @@ -15,10 +15,9 @@ class Search_model extends CI_Model { JOIN album ON track.albumid = album.id JOIN artist ON album.artistid = artist.id JOIN cover ON album.coverid = cover.id - WHERE song.name LIKE '%$query%' + WHERE song.name LIKE ? ORDER BY song.name ASC"; - - $query = $this->db->query($sql); + $query = $this->db->query($sql, array('%' . $query . '%')); return $query->result(); } @@ -28,22 +27,21 @@ class Search_model extends CI_Model { JOIN artist ON album.artistid = artist.id JOIN genre ON album.genreid = genre.id JOIN cover ON album.coverid = cover.id - WHERE album.name LIKE '%$query%' + WHERE album.name LIKE ? ORDER BY album.name ASC"; - - $query = $this->db->query($sql); + $query = $this->db->query($sql, array('%' . $query . '%')); return $query->result(); } public function searchGenres($query){ - $sql = "SELECT id, name FROM genre WHERE name LIKE '%$query%' ORDER BY name ASC"; - $query = $this->db->query($sql); + $sql = "SELECT id, name FROM genre WHERE name LIKE ? ORDER BY name ASC"; + $query = $this->db->query($sql, array('%' . $query . '%')); return $query->result(); } public function searchArtistes($query){ - $sql = "SELECT id, name FROM artist WHERE name LIKE '%$query%' ORDER BY name ASC"; - $query = $this->db->query($sql); + $sql = "SELECT id, name FROM artist WHERE name LIKE ? ORDER BY name ASC"; + $query = $this->db->query($sql, array('%' . $query . '%')); return $query->result(); } } diff --git a/CodeIgniter-3.1.13/application/views/artists_list.php b/CodeIgniter-3.1.13/application/views/artists_list.php index 6310747..e77137d 100644 --- a/CodeIgniter-3.1.13/application/views/artists_list.php +++ b/CodeIgniter-3.1.13/application/views/artists_list.php @@ -3,7 +3,7 @@
- +