vraiment beau boulot
This commit is contained in:
parent
c61c485651
commit
17a95f32ce
codeigniter/application
21
codeigniter/application/controllers/Artistes.php
Normal file
21
codeigniter/application/controllers/Artistes.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Artistes extends CI_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->model('model_music');
|
||||
$this->load->helper('html');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('form');
|
||||
}
|
||||
public function index(){
|
||||
$artistes = $this->model_music->getArtistes();
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('artistes_list', ['artistes'=>$artistes]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,4 +17,17 @@ class Model_music extends CI_Model {
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getArtistes(){
|
||||
$query = $this->db->query(
|
||||
"SELECT artist.id AS artistId, artist.name AS artistName, album.name AS albumName, album.year, cover.jpeg
|
||||
FROM album
|
||||
INNER JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
GROUP BY artist.name, album.year
|
||||
"
|
||||
);
|
||||
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
|
30
codeigniter/application/views/artistes_list.php
Normal file
30
codeigniter/application/views/artistes_list.php
Normal file
@ -0,0 +1,30 @@
|
||||
<h5>Artistes list</h5>
|
||||
<section class="list">
|
||||
<?php
|
||||
$artistAlbums = array();
|
||||
|
||||
foreach ($artistes as $artist) {
|
||||
|
||||
if (!array_key_exists($artist->artistName, $artistAlbums)) {
|
||||
$artistAlbums[$artist->artistName] = array();
|
||||
}
|
||||
$artistAlbums[$artist->artistName][] = array(
|
||||
'albumName' => $artist->albumName,
|
||||
'year' => $artist->year
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($artistAlbums as $artistName => $albums) {
|
||||
echo "<div><article>";
|
||||
echo "<header class='short-text'>";
|
||||
echo "<h2>$artistName</h2>";
|
||||
echo "</header>";
|
||||
echo "<ul>";
|
||||
foreach ($albums as $album) {
|
||||
echo "<li>" . $album['albumName'] . " - " . $album['year'] . "</li>";
|
||||
}
|
||||
echo "</ul>";
|
||||
echo "</article></div>";
|
||||
}
|
||||
?>
|
||||
</section>
|
Loading…
x
Reference in New Issue
Block a user