1
I’m creating a project and I ran into a problem.
The idea is this: add participants to a specific event.
I’ve created everything right: controllers, models and views.
My question is how do I make the controller/model receive the id’s of each participant I selected in a multi-select
view adicionar_participante
.
I have a table (participation_events) whose columns are:
id_relação
, id_usuario
, id_evento
.
So for each participant in an event I have a relation 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>
Code of the Event Controller:
<?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(
'' => '';
);
}
}
Code of the Model Events:
<?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;
}
}
Edit the question and add the controller codes and database templates. Does Codeigniter have native support for model relations? In fact, as it is new here, I suggest you do the [tour] to learn the basics of how the site works. It is always useful.
– Woss
I assume you’re sending this data through a form in your view, and if so, are you able to get that data from the controller? not only enter the codes of your controller and model, but also your view tbm.
– Marcelo Diniz
@Marcelodiniz already added the codes. They are basic, I’m learning now PHP and Codeigniter.
– Gabriel Alcala
@Andersoncarloswoss already added.
– Gabriel Alcala