tp5 mvc + codeigniter v3
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
.action{
|
||||
text-align : right;
|
||||
}
|
||||
.action a {
|
||||
margin-right : 1rem;
|
||||
}
|
||||
table {
|
||||
|
||||
font-size : 1.5rem;
|
||||
}
|
||||
body {
|
||||
padding : 2rem;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Todo extends CI_Controller {
|
||||
public $filter = 'all';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->helper('html');
|
||||
$this->load->helper('url');
|
||||
$this->load->helper('form');
|
||||
|
||||
$this->load->model('model_todo');
|
||||
|
||||
$this->filter = $this->input->get('filter') ?? 'all';
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$todos = $this->model_todo->getTodos($this->filter);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('todos',['todos'=>$todos,'filter'=>$this->filter]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public function toggle($id)
|
||||
{
|
||||
$this->model_todo->toggleTodo($id);
|
||||
redirect('/todo');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$todo = ['text'=>$this->input->post('todo'),'done'=>0];
|
||||
$this->model_todo->addTodo($todo);
|
||||
$todos = $this->model_todo->getTodos();
|
||||
$this->index();
|
||||
}
|
||||
public function edit($id)
|
||||
{
|
||||
|
||||
$this->load->library('form_validation');
|
||||
$this->load->model('model_todo');
|
||||
|
||||
$todo = $this->model_todo->getTodo($id);
|
||||
$this->form_validation->set_rules('todo', 'Todo', 'required');
|
||||
if ($this->form_validation->run() === FALSE){
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('edit',['todo'=>$todo]);
|
||||
$this->load->view('layout/footer');
|
||||
|
||||
|
||||
}else{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class User extends CI_Controller {
|
||||
|
||||
public function create()
|
||||
{
|
||||
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_rules('nom', 'Nom', 'required');
|
||||
$this->form_validation->set_rules('prenom', 'Prénom', 'required');
|
||||
$this->form_validation->set_rules('email', 'Adresse mail', 'valid_email');
|
||||
$this->form_validation->set_rules('password', 'current password', 'min_length[5]|required');
|
||||
$this->form_validation->set_rules('cpassword', 'confirm password', 'required|matches[password]');
|
||||
|
||||
|
||||
if ($this->form_validation->run() === FALSE){
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('create_user_form');
|
||||
$this->load->view('layout/footer');
|
||||
}else{
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
public function auth()
|
||||
{
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Model_todo extends CI_Model {
|
||||
public function __construct()
|
||||
{
|
||||
$this->load->database();
|
||||
}
|
||||
public function deleteTodo($id)
|
||||
{
|
||||
$this->db->delete('todo',['id'=>$id]);
|
||||
}
|
||||
|
||||
public function getTodos($filter='all')
|
||||
{
|
||||
$where_filter = ["done" => 1, "active" => 0, "all" => "%"];
|
||||
return $this
|
||||
->db
|
||||
->query("SELECT * FROM todo WHERE done LIKE ?",[$where_filter[$filter]])
|
||||
->result();
|
||||
}
|
||||
|
||||
public function toggleTodo($id){
|
||||
|
||||
/* en utilisant Query Builder class
|
||||
* $this
|
||||
->db
|
||||
->set('done','1-done',false)
|
||||
->where('id',$id)
|
||||
->update('todo');
|
||||
*/
|
||||
|
||||
$sql = "UPDATE todo SET done = 1 - done WHERE id = ?";
|
||||
$this
|
||||
->db
|
||||
->query($sql,[$id]);
|
||||
}
|
||||
|
||||
public function editTodo($id,$text)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public function getTodo($id){
|
||||
$sql = "SELECT * FROM todo where id = ?";
|
||||
return $this
|
||||
->db
|
||||
->query($sql,[$id])->row();
|
||||
}
|
||||
|
||||
public function addTodo($todo)
|
||||
{
|
||||
$this->db->insert('todo', $todo);
|
||||
return $this
|
||||
->db
|
||||
->insert_id();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
<?=validation_errors(); ?>
|
||||
<?=form_open('user/create')?>
|
||||
<!-- Grid -->
|
||||
<div class="grid">
|
||||
|
||||
<!-- Markup example 1: input is inside label -->
|
||||
<label for="prenom">
|
||||
Prénom
|
||||
<input type="text" id="prenom" name="prenom" placeholder="Prénom" value="<?=set_value('prenom')?>"required>
|
||||
</label>
|
||||
|
||||
<label for="nom">
|
||||
Nom
|
||||
<input type="text" id="nom" name="nom" placeholder="nom" value="<?=set_value('nom')?>" required>
|
||||
</label>
|
||||
</div>
|
||||
<!-- Markup example 2: input is after label -->
|
||||
<label for="email">Adresse mail</label>
|
||||
<input type="email" id="email" name="email" placeholder="Email" value="<?=set_value('email')?>" required>
|
||||
<div class="grid">
|
||||
<label for="password">Password
|
||||
<input type="password" id="password" name="password" placeholder="Password" value="<?=set_value('password')?>" required>
|
||||
</label>
|
||||
<label for="password">Confirmation password
|
||||
<input type="password" id="cpassword" name="cpassword" placeholder="Password" value="<?=set_value('cpassword')?>" required>
|
||||
</label>
|
||||
|
||||
</div>
|
||||
<!-- Button -->
|
||||
<button type="submit">Submit</button>
|
||||
|
||||
</form>
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
<article>
|
||||
<?php echo form_open("/todo/edit/{$todo->id}");?>
|
||||
<form>
|
||||
<label for="email">Todo
|
||||
<input type="text" name="todo" value="<?=set_value('todo',$todo->text)?>" required>
|
||||
</label>
|
||||
|
||||
<!-- Button -->
|
||||
<button type="submit">Submit</button>
|
||||
|
||||
</form>
|
||||
</article>
|
||||
@@ -0,0 +1,3 @@
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>TODO APP</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||
/>
|
||||
<!--link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css"-->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<?=link_tag('assets/style.css')?>
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
@@ -0,0 +1,39 @@
|
||||
<article>
|
||||
<header>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><strong>TODOS</strong></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><?=anchor("todo/?filter=all",'All',['role'=>($filter=='all'?'button':'')])?></li>
|
||||
<li><?=anchor("todo/?filter=active",'Active',['role'=>($filter=='active'?'button':'')])?></li>
|
||||
<li><?=anchor("todo/?filter=done",'Done',['role'=>($filter=='done'?'button':'')])?></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<?=form_open('todo/add')?>
|
||||
<input type="text" placeholder="todo" name="todo">
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<?php foreach($todos as $todo): ?>
|
||||
<?php if ($todo->done): ?>
|
||||
<tr>
|
||||
<td><s><?=$todo->text?></s></td>
|
||||
<td class='action'>
|
||||
<?=anchor("todo/toggle/{$todo->id}", '<i class="fa fa-toggle-on"></i>')?>
|
||||
<?=anchor("todo/delete/{$todo->id}", '<i class="fa fa-trash-o"></i>')?>
|
||||
<?=anchor("todo/edit/{$todo->id}", '<i class="fa fa-edit"></i>')?>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<tr><td><?=$todo->text?></td>
|
||||
<td class='action'>
|
||||
<?=anchor("todo/toggle/{$todo->id}", '<i class="fa fa-toggle-off"></i>')?>
|
||||
<?=anchor("todo/delete/{$todo->id}", '<i class="fa fa-trash-o"></i>')?>
|
||||
<?=anchor("todo/edit/{$todo->id}", '<i class="fa fa-edit"></i>')?>
|
||||
<?php endif; ?>
|
||||
</td></tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</article>
|
||||
@@ -0,0 +1,65 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 5.2.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Hôte : localhost
|
||||
-- Généré le : mar. 23 mai 2023 à 07:22
|
||||
-- Version du serveur : 10.11.2-MariaDB
|
||||
-- Version de PHP : 8.2.4
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Structure de la table `todo`
|
||||
--
|
||||
|
||||
CREATE TABLE `todo` (
|
||||
`id` int(11) NOT NULL,
|
||||
`text` varchar(256) NOT NULL,
|
||||
`done` tinyint(1) NOT NULL DEFAULT 0
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Déchargement des données de la table `todo`
|
||||
--
|
||||
|
||||
INSERT INTO `todo` (`id`, `text`, `done`) VALUES
|
||||
(1, 'Avoid excessive caffeine !', 0),
|
||||
(2, 'Be less provocative !', 1),
|
||||
(3, 'Be nice to people', 1);
|
||||
|
||||
--
|
||||
-- Index pour les tables déchargées
|
||||
--
|
||||
|
||||
--
|
||||
-- Index pour la table `todo`
|
||||
--
|
||||
ALTER TABLE `todo`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT pour les tables déchargées
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT pour la table `todo`
|
||||
--
|
||||
ALTER TABLE `todo`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=58;
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
Reference in New Issue
Block a user