Files
SAE_PHP_2024/CodeIgniter-3.1.13/application/controllers/Playlist.php

51 lines
1.6 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Playlist extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('model_music');
$this->load->library('form_validation');
}
public function index(){
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
$playlists = $this->model_music->getPlaylist();
}else{
$recherche=filter_input(INPUT_GET,'recherche');
$playlists = $this->model_music->getSearchPlaylist($recherche);
}
$this->load->view('layout/header');
if ($playlists == false){
$page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
$this->load->view('error',['page'=>$page[count($page)-1]]);
$playlists = $this->model_music->getPlaylist();
}
$this->load->view('playlist_list',['playlists'=>$playlists]);
$this->load->view('layout/footer');
}
public function addplaylist(){
$this->form_validation->set_rules('name', 'name', 'required');
if ($this->form_validation->run() == FALSE){
$this->load->view('layout/header');
$this->load->view('create_playlist');
$this->load->view('layout/footer');
}else{
$nom = $this->input->post('name');
$description = $this->input->post('Description');
$userId = $this->session->userdata('userId');
$playlist = array(
'name'=>$nom,
'description'=>$description,
'userId'=>$userId,
);
$this->model_music->addPlayliste($playlist);
redirect('playlist');
}
}
}