I'm creating a project and I ran into a problem.
The idea is to add participants to a specific event.
I've created everything right: controllers, models and views.
My question is how do I get the controller / model to receive the id's of each participant I selected in a multi-select
view adicionar_participante
.
I have a table (attendees_events) whose columns are:
id_relação
, id_usuario
, id_evento
.
So for each participant in an event I have a relationship in this table.
VIEW Code:
<h1>Adicionar participantes</h1>
<form action="adicionar-participante-evento" method="post">
<select multiple class="form-control" name="id_usuario">
<?php foreach ($usuarios as $usuario) { ?>
<option value="<?= $usuario['id_usuario']; ?>"><?= $usuario['nome_usuario']; ?></option>
<?php
}
?>
</select>
<button class="btn btn-default" type="submit">Adicionar</button>
</form>
Event Controller Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class EventoController extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->view('template/cabecalho');
$this->load->view('template/footer');
}
public function index() {
$eventos = $this->EventosModel->listarTodos();
$dadosEventos = array('eventos' => $eventos );
$this->load->view('eventos/index', $dadosEventos);
}
public function adicionarParticipante(){
$usuarios = $this->UsuariosModel->listarTodos();
$dadosUsuarios = array('usuarios' => $usuarios);
$this->load->view('eventos/adicionar_participante', $dadosUsuarios);
}
public function adicionarParticipanteEvento(){
$id_usuarios_participantes = array(
'' => '';
);
}
}
Event Model Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class EventosModel extends CI_Model {
public function listarTodos(){
$eventos = $this->db->get('eventos')->result_array();
return $eventos;
}
}