Good evening, I’m new to codeigniter 4 and I want to make an application.
I can’t make a dropdown select option value, can you help me?
I have the structure that I have been struggling with for several hours to understand how it works
appModulesTaskModelsClientModel.php
namespace AppModels;
class ClientModel extends BaseModel
{
protected $table = 'client';
protected $primaryKey = 'id_client';
protected $allowedFields = [
'cl_first_name',
'cl_last_name',
'cl_name_company',
'cl_logo_img',
'cl_addres',
'cl_banck_name',
'cl_banck_id_number',
'cl_data_add',
'cl_data_mdf'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}
appModulesTaskControllersTask.php
namespace AppModulesTaskControllers;
use AppControllersBaseController;
use AppModulesTaskModelsTaskModel;
use AppModulesTaskModelsClientModel;
/**
* Class Task
*/
class Task extends BaseController
{
private $task_model;
private $client_model;
function __construct()
{
$this->task_model = new TaskModel();
$this->client_model = new ClientModel();
}
public function index() {
$data['client'] = $this->client_model->select('id_client,cl_first_name,cl_last_name,cl_name_company,cl_logo_img,cl_addres,cl_banck_name,cl_banck_id_number')->findAll();
appModulesTaskViewstaskform.php
<div class="col-md-12">
<div class="form-group">
<label for="client" class="text-dark">Client</label>
<?php $id_select = (isset($obj)) ? $obj['id_client'] : set_value('cl_first_name');?>
<select name="client" id="client" class="form-control">
<?php foreach($client??[] as $item): ?>
<?php if ($item['type'] == "backend") : ?>
<option value="<?=$item['cl_first_name']?>" <?= $id_select == $item['cl_first_name'] ? 'selected' : '' ?>><?=$item['id_client']?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Form -->
<script>
$(document).ready(function () {
"use strict";
$('#title').focus();
$("#client").select2();
});
</script>