Welcome Guest, Not a member yet? Register   Sign In
  Retrieving the results of a selectSum query
Posted by: davecoventry - 09-15-2023, 02:22 AM - Replies (3)

I am trying to find the sum total of a table column. The table contains details of documents including the file sizes which are in a column called 'dsize'.
Accoding to https://codeigniter.com/user_guide/datab...ilder.html, $builder->selectSum() should give me what I want.

The documentation is as follows:

PHP Code:
<?php 
PHP Code:
$builder->selectSum('age'); 
PHP Code:
$query $builder->get(); 
PHP Code:
// Produces: SELECT SUM(age) as age FROM mytable 

That is all.
Using this example:
PHP Code:
    $builder=$this->db->table('drawings');
    $builder->selectSum('dsize');
    $query=$builder->get(); 
The contents of $query - as revealed by print_r() - are as follows:
Code:
CodeIgniter\Database\MySQLi\Result Object
(
    [connID] => mysqli Object
        (
            [affected_rows] => 1
            [client_info] => mysqlnd 8.1.2-1ubuntu2.14
            [client_version] => 80102
            [connect_errno] => 0
            [connect_error] =>
            [errno] => 0
            [error] =>
            [error_list] => Array
                (
                )

            [field_count] => 1
            [host_info] => Localhost via UNIX socket
            [info] =>
            [insert_id] => 0
            [server_info] => 5.5.5-10.6.12-MariaDB-0ubuntu0.22.04.1-log
            [server_version] => 100612
            [sqlstate] => 00000
            [protocol_version] => 10
            [thread_id] => 18379
            [warning_count] => 0
        )

    [resultID] => mysqli_result Object
        (
            [current_field] => 0
            [field_count] => 1
            [lengths] =>
            [num_rows] => 1
            [type] => 0
        )

    [resultArray] => Array
        (
        )

    [resultObject] => Array
        (
        )

    [customResultObject] => Array
        (
        )

    [currentRow] => 0
    [numRows:protected] =>
    [rowData] =>
)
The 'drawings' table is as follows:
Code:
id |  name      |       date          | dsize
-----------------------------------------------------
3  | Berta Road | 2022-11-14 19:54:10 | NULL
6  | LaDePa pla | 2023-04-25 12:57:34 | NULL
7  | LYCOPODIUM | 2023-05-31 16:13:50 | NULL
8  | DRA GLOBAL | 2023-06-21 10:15:35 | NULL
9  | DRA GLOBAL | 2023-06-21 10:15:36 | NULL
10 | ADP 2440   | 2023-07-28 20:15:05 | 526528
11 | ADP 2440   | 2023-07-29 07:11:42 | 683072
12 | D G Steel  | 2023-07-29 10:08:41 | 528288
13 | DG Steel   | 2023-07-29 10:08:44 | 1054304

I really can't see how to get the total file size from the table.


  Error 'Can't find a route for GET' on Ajax POST
Posted by: legendarypokemon69 - 09-14-2023, 08:14 PM - Replies (6)

Every time I submit a form, I get an error Can't find a route for 'get: produk/tambahProduk'.
I have set up routes and ajax with post, why I get that error?

Route.php:

Code:
<?php

use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->get('/', 'home');
$routes->get('home', 'home');
$routes->get('produk', 'Produk::index');
$routes->get('produk/getProduk', 'Produk::getProduk');
$routes->get('instansi/getInstansi', 'Instansi::getInstansi');
$routes->get('produk/getProdukAll', 'Produk::getProdukAll');
$routes->get('produk/getProdukJenis', 'Produk::getProdukJenis');
$routes->post('produk/tambahProduk', 'Produk::tambahProduk');
// $routes->match(['get', 'post'], 'instansi/getInstansi', 'Instansi::getInstansi');

service('auth')->routes($routes);

AJAX:
Code:
$('#formProduk').submit(function (e) {
    e.preventDefault();
    var method = '';
    var id_produk = $("[name=id_produk]").val();

    if (id_produk == '') {
      method = 'tambah';
    } else {
      method = 'ubah';
    }

    $.ajax({
      url: siteurl + "produk/" + method + "Produk",
      type: "post",
      data: $(this).serialize(),
      dataType: 'json',
      beforeSend: function () {

      },
      complete: function () {

      },
      success: function (response) {
        if (response.error) {
          // $.each(response.error, function (key, value) {
          //  // console.log(key);
          // })
         
          if (response.error.tentang) {$('[name="tentang"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.tentang);}
          else{$('[name="tentang"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}

          if (response.error.nomor) {$('[name="nomor"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.nomor);}
          else{$('[name="nomor"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.tahun) {$('[name="tahun"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.tahun);}
          else{$('[name="tahun"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.jenis_id) {$('[name="jenis_id"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.jenis_id);}
          else{$('[name="jenis_id"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.tempat_penetapan) {$('[name="tempat_penetapan"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.tempat_penetapan);}
          else{$('[name="tempat_penetapan"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.tgl_penetapan) {$('[name="tgl_penetapan"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.tgl_penetapan);}
          else{$('[name="tgl_penetapan"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.tgl_undang) {$('[name="tgl_undang"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.tgl_undang);}
          else{$('[name="tgl_undang"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.bidang) {$('[name="bidang"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.bidang);}
          else{$('[name="bidang"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.sumber) {$('[name="sumber"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.sumber);}
          else{$('[name="sumber"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.pemrakarsa) {$('[name="pemrakarsa"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.pemrakarsa);}
          else{$('[name="pemrakarsa"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.ttd) {$('[name="ttd"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.ttd);}
          else{$('[name="ttd"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.urusan) {$('[name="urusan"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.urusan);}
          else{$('[name="urusan"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.bahasa) {$('[name="bahasa"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.bahasa);}
          else{$('[name="bahasa"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.subjek) {$('[name="subjek"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.subjek);}
          else{$('[name="subjek"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          if (response.error.teu) {$('[name="teu"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.teu);}
          else{$('[name="teu"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
         
          // if (response.error.file) {$('[name="file"]').addClass('is-invalid').nextAll('.invalid-feedback:first').html(response.error.file);}
          // else{$('[name="file"]').removeClass('is-invalid').nextAll('.invalid-feedback:first').html('');}
          console.log('masih eror');
          console.log(response.error);
        }else{
          Swal.fire("Sukses", response.sukses, "success");
          $("#modalFormProduk").modal("hide");
          $("#tb_produk").DataTable().ajax.reload();
          console.log('harusnya bisa');
        }
        // console.log($('[name="nomor"]').val());
      },
      error: function (xhr, ajaxOptions, thrownError) {
        console.log($("[name=produk]").val());
        Swal.fire("Error!", xhr.status + "\n" + xhr.responseText + "\n" + thrownError, "warning");
      },
    }).done(function (resp) {
      // spinner.hide();
    });
  });

Controller:
Code:
function tambahProduk()
{
if ($this->request->isAJAX()) {
$validation = \Config\Services::validation();

$valid = $this->validate([
'jenis_id' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Jenis tidak boleh kosong.']],
'tentang' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Tentang tidak boleh kosong.']],
'nomor' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Nomor tidak boleh kosong.']],
'tahun' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Tahun tidak boleh kosong.']],
'bidang' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Bidang tidak boleh kosong.']],
'tempat_penetapan' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Tempat Penetapan tidak boleh kosong.']],
'tgl_penetapan' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Tanggal Penetapan tidak boleh kosong.']],
'tgl_undang' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Tanggal Pengundangan tidak boleh kosong.']],
'sumber' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Sumber tidak boleh kosong.']],
'pemrakarsa' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Pemrakarsa tidak boleh kosong.']],
'ttd' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Penandatangan tidak boleh kosong.']],
'urusan' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Urusan tidak boleh kosong.']],
'bahasa' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Bahasa tidak boleh kosong.']],
'teu' => ['rules' => 'required', 'errors' => ['required' => 'Kolom T.E.U. tidak boleh kosong.']],
'subjek' => ['rules' => 'required', 'errors' => ['required' => 'Kolom Subjek tidak boleh kosong.']],
]);

if (!$valid) {
$msg = ['error' => [
'jenis_id' => $validation->getError('jenis_id'),
'tentang' => $validation->getError('tentang'),
'nomor' => $validation->getError('nomor'),
'tahun' => $validation->getError('tahun'),
'bidang' => $validation->getError('bidang'),
'tempat_penetapan' => $validation->getError('tempat_penetapan'),
'tgl_penetapan' => $validation->getError('tgl_penetapan'),
'tgl_undang' => $validation->getError('tgl_undang'),
'sumber' => $validation->getError('sumber'),
'pemrakarsa' => $validation->getError('pemrakarsa'),
'ttd' => $validation->getError('ttd'),
'urusan' => $validation->getError('urusan'),
'bahasa' => $validation->getError('bahasa'),
'teu' => $validation->getError('teu'),
'subjek' => $validation->getError('subjek'),
// 'produk' => $validation->getError('produk'),
]];
echo json_encode($msg);
} else {
$file_produk = $this->request->getFile('produk');
$file_produk->move('assets/doc/produk');
$produk = $file_produk->getName();

$dataproduk = [
'jenis_id' => $this->request->getVar('jenis_id'),
'tentang' => $this->request->getVar('tentang'),
'nomor' => $this->request->getVar('nomor'),
'tahun' => $this->request->getVar('tahun'),
'bidang' => $this->request->getVar('bidang'),
'tempat_penetapan' => $this->request->getVar('tempat_penetapan'),
'tgl_penetapan' => $this->request->getVar('tgl_penetapan'),
'tgl_undang' => $this->request->getVar('tgl_undang'),
'sumber' => $this->request->getVar('sumber'),
'pemrakarsa' => $this->request->getVar('pemrakarsa'),
'ttd' => $this->request->getVar('ttd'),
'urusan' => $this->request->getVar('urusan'),
'bahasa' => $this->request->getVar('bahasa'),
'teu' => $this->request->getVar('teu'),
'subjek' => $this->request->getVar('subjek'),
// 'uji_materi' => $this->request->getVar('uji_materi'),
'produk' => $produk,
// 'abstrak' => $this->request->getVar('abstrak'),
// 'status' => $this->request->getVar('status'),
];

$this->p->insert($dataproduk);
$msg = [
'sukses' => 'Data berhasil disimpan.'
];

echo json_encode($msg);
}
} else {
exit('Maaf tidak dapat diproses');
}
}

Form:
Code:
<form method="POST" id="formProduk" enctype="multipart/form-data">
<?= csrf_field() ?>
<input type="text" id="id_produk" name="id_produk" style="display: none">
<div class="row gy-2">
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="tentang">Tentang</label>
<div class="form-control-wrap">
<textarea class="form-control no-resize" name="tentang" placeholder="Tentang"></textarea>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-md-8">
<div class="row gy-2">
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="nomor">Nomor</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="nomor" placeholder="Nomor">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="tahun">Tahun</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="tahun" placeholder="Tahun">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="jenis_id">Jenis</label>
<div class="form-control-wrap ">
<div class="form-control-select">
<select class="select-produk-jenis" name="jenis_id" placeholder="Pilih Jenis Produk">
</select>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="tempat_penetapan">Tempat Penetapan</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="tempat_penetapan" value="Pekalongan" placeholder="Tempat Penetapan">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label">Tanggal Penetapan</label>
<div class="form-control-wrap">
<div class="form-icon form-icon-left">
<em class="icon ni ni-calendar"></em>
</div>
<input type="text" class="form-control date-picker" name="tgl_penetapan" data-date-format="dd-mm-yyyy" placeholder="Tanggal Penetapan" autocomplete="off">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label">Tanggal Pengundangan</label>
<div class="form-control-wrap">
<div class="form-icon form-icon-left">
<em class="icon ni ni-calendar"></em>
</div>
<input type="text" class="form-control date-picker" name="tgl_undang" data-date-format="dd-mm-yyyy" placeholder="Tanggal Pengundangan" autocomplete="off">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="row gy-2">
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="bidang">Bidang</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="bidang" placeholder="Bidang">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="sumber">Sumber</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="sumber" placeholder="Sumber">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="pemrakarsa">Pemrakarsa</label>
<div class="form-control-wrap ">
<div class="form-control-select">
<select class="select-instansi" name="pemrakarsa" placeholder="Pilih Instansi">
</select>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="ttd">Penandatangan</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="ttd" placeholder="Penandatangan">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="urusan">Urusan</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="urusan" placeholder="Urusan">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="bahasa">Bahasa</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="bahasa" value="Indonesia" placeholder="Bahasa">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="subjek">Subjek</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="subjek" placeholder="Subjek">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="teu">T.E.U.</label>
<div class="form-control-wrap">
<input type="text" class="form-control" name="teu" placeholder="Tajuk Entry Utama">
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="uji_materi">Uji Materi</label>
<div class="form-control-wrap">
<div class="form-file">
<input type="file" class="form-file-input" name="uji_materi">
<label class="form-file-label" for="uji_materi">Pilih berkas</label>
<input type="text" class="form-control" name="uji_materis" placeholder="Belum ada berkas." disabled>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="abstrak">Abstrak</label>
<div class="form-control-wrap">
<div class="form-file">
<input type="file" class="form-file-input" name="abstrak">
<label class="form-file-label" for="abstrak">Pilih berkas</label>
<input type="text" class="form-control" name="abstraks" placeholder="Belum ada berkas." disabled>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="file">File Produk</label>
<div class="form-control-wrap">
<div class="form-file">
<input type="file" class="form-file-input" name="produk">
<label class="form-file-label" for="produk">Pilih berkas</label>
<input type="text" class="form-control" name="produks" placeholder="Belum ada berkas." disabled>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="status_akhir">Status</label>
<div class="form-control-wrap ">
<div class="form-control-select">
<select class="select-biasa" name="status_akhir">
<option value="Berlaku">Berlaku</option>
<option value="Tidak Berlaku">Tidak Berlaku</option>
</select>
</div>
</div>
</div>
</div>
</div>
<br>
<div id="ket_status" class="row gy-2">
<?php for ($i = 0; $i < 8; $i++) { ?>
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="status">Keterangan Status</label>
<div class="form-control-wrap ">
<div class="form-control-select">
<select class="select-biasa" name="status[]" placeholder="Pilih Keterangan Status">
<option value=""></option>
<option value="Mencabut">Mencabut</option>
<option value="Dicabut">Dicabut</option>
<option value="Mengubah">Mengubah</option>
<option value="Diubah">Diubah</option>
</select>
</div>
<div class="form-control-select">
<select class="select-produk" name="status_id[]" placeholder="Pilih Produk">
</select>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<br>
<div class="row gy-2">
<div class="col-sm-3">
<div class="form-group">
<label class="form-label" for="catatan">Catatan</label>
<div class="form-control-wrap">
<textarea class="form-control no-resize" name="catatan" placeholder="Catatan"></textarea>
</div>
</div>
</div>
</div>
<br>
<div class="row gy-2">
<div class="col-sm-12" align="right">
<button type="submit" class="btn btn-primary" id="btnTambahProduk">Simpan</button>
<button type="submit" class="btn btn-primary" id="btnUbahProduk">Simpan</button>
<button type="button" class="btn btn-danger" id="btnBatalProduk" data-bs-dismiss="modal">Batal</button>
</div>
</div>
</form>
Thanks in advance.


  Problem with filters
Posted by: motoroller - 09-14-2023, 02:21 PM - Replies (1)

Hello everyone, i use few filters in project, one global and one in some routers

In Config/Filters i have global

PHP Code:
public array $globals = [

        'before' => [

            'isLoggedIn' => [

                'except' => [
                    'admin*'
]

]

]; 

public bool $multipleFilters = true;

When i load this: $routes->get('/', [Start::class, 'Index'], [ 'filter' => 'isBlocked' ]);  router my local "isBlocked" filter is working, but my global filter "isLoggedIn" is not execute why? Before is working properly but after update is not(

Then i have added to Filters

PHP Code:
public array $filters = [
        'isBlocked' => ['before' => ['start']]
    ]; 
but filters "isBlocked" is not working as well(


  Unable to install codeigniter4/appstarter
Posted by: DejaDingo - 09-14-2023, 09:50 AM - Replies (4)

I have several working local installations of CodeIgniter 4, but wanted to setup a base project from which to test deployment to a shared server.
My local machine uses WAMP, so my path cannot include PHP, therefore it needs to be set in my PowerShell.  Running the standard composer install for this package succeeds in creating the project directory and installing the appstarter pieces, but then it gets stuck trying to use composer to load the rest of the dependencies.  Indeed trying to run an update on any of my other local projects suffers the same hang.  Here is the transcript from the installation.

Quote:Windows PowerShell
Copyright © Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\sherry> k:
PS K:\> Set-PHPVersion 82
PHP 8.2.7 (cli) (built: Jun  7 2023 10:25:38) (ZTS Visual C++ 2019 x64)
Copyright © The PHP Group
Zend Engine v4.2.7, Copyright © Zend Technologies
PS K:\> composer --version
Composer version 2.5.8 2023-06-09 17:13:21
PS K:\> cd sites
PS K:\sites> composer create-project codeigniter4/appstarter
Creating a "codeigniter4/appstarter" project at "./appstarter"
Info from https://repo.packagist.org: #StandWithUkraine
Installing codeigniter4/appstarter (v4.4.1)
  - Installing codeigniter4/appstarter (v4.4.1): Extracting archive
Created project in K:\sites\appstarter
Loading composer repositories with package information

UPDATE:
This appears to be a problem with PHP 8.1 and PHP 8.2. The update works with PHP 7.4.33 and also with PHP 8.0.28, although the missing ZIP extension in PHP 8.0 is a problem.

Any ideas why composer update does not seem to work in PHP 8.1 or PHP 8.2?


  Modules in CI4 - Helpers and Constants
Posted by: encodedigital - 09-14-2023, 08:58 AM - Replies (3)

Hi All,
I am currently working on a project, where I am keeping all my code in a module. So my structure is as below:

Code:
-app
-mymodule
  -admin
    -Config
      -Constants.php
    -Helpers
      -functions_helper.php
  -frontend
-public
-vendor
.... (other standard folders)

Now everything else from Modules (Routes, Controllers, Views) is working fine as I have provided namespace in Autoload.php, but Helpers and Constants are not working as they are not classes. 
In app > Config > autoload.php, I tried to add files as well with correct path, but it is still not working.
Code:
public $files = [
        '/mymodule/admin/Helpers/functions_helper.php'
    ];

I can make it work if I make them classes, but before I do that way, I want to check how to make it work without making classes. 
I read CI guide at https://codeigniter4.github.io/userguide...ml#helpers , where it is written that "Helpers will be automatically discovered within defined namespaces when using the 
Code:
helper() 
function, as long as it is within the namespaces [b]Helpers[/b] directory:"
But it is not working. I tried that way as well in the Controller.

Code:
helper('MyModule\Admin\Helpers\functions');

Any idea from anyone?


  404 can't find route
Posted by: risk - 09-14-2023, 02:52 AM - Replies (4)

Hello,
so in the past I always set up my apache (XAMPP) root directory to point to the public folder of my project. But now I am working on several projects at the same time, so I set my DocumentRoot back to D:/xampp/htdocs/
In my project I set the base url inside the App.php like this: 

PHP Code:
public string $baseURL 'http://localhost/agb/project-root/public/'

Since my projectstructure is the following:
-agb
  -project-root
    -app
    -public
    -tests
    -vendor
    -writable
    -.env
    -builds
    -composer.json
    -composer.lock
    -phpunit.xml.dist
    -preload.php
    -spark

However I always get a 404 error when loading another page, than the homepage. The error message is
Can't find a route for 'get: agb/project-root/public/route'.
route can be replaced by any url I want, it is always the same error.

My routes inside the Routes.php are configured like this:
PHP Code:
$routes->match(['get''post'], 'route/(:any)''Controller::Method/$1');
$routes->get('route''Controller::Method'); 

Where route, Controller and Method are replaced with real Classes and methods.

The thing is: as soon as I add an index.php to my url ( e.g. http://localhost/agb/project-root/public....php/route ) the site is loaded successfully without any errors.

Why do I have this strange error? Could you please help me?


  Session GC issues - unlink
Posted by: ValdisM - 09-14-2023, 01:05 AM - Replies (4)

Hi,
We lately get a lot of these messages in our error logs. Maybe you can help to understand why it is happening?

CRITICAL - 2023-09-13 23:59:01 --> unlink(/home/XXX/public_html/writable/session/ci_session068adef747836ce9510a1eda008e44ae34588419): No such file or directory in SYSTEMPATH/Session/Handlers/FileHandler.php on line 299.
1 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'unlink(/home/XXX/public_html/writable/session/ci_session068adef747836ce9510a1eda008e44ae34588419): No such file or directory', 'SYSTEMPATH/Session/Handlers/FileHandler.php', 299)
2 SYSTEMPATH/Session/Handlers/FileHandler.php(299): unlink('ROOTPATH/writable/session/ci_session068adef747836ce9510a1eda008e44ae34588419')
3 [internal function]: CodeIgniter\Session\Handlers\FileHandler->gc(7200)
4 SYSTEMPATH/Session/Session.php(928): session_start()
5 SYSTEMPATH/Session/Session.php(250): CodeIgniter\Session\Session->startSession()
6 SYSTEMPATH/Config/Services.php(674): CodeIgniter\Session\Session->start()
7 SYSTEMPATH/Config/BaseService.php(252): CodeIgniter\Config\Services::session(Object(Config\App), false)
8 SYSTEMPATH/Config/BaseService.php(193): CodeIgniter\Config\BaseService::__callStatic('session', [...])
9 SYSTEMPATH/Config/Services.php(641): CodeIgniter\Config\BaseService::getSharedInstance('session', null)
10 SYSTEMPATH/Config/BaseService.php(252): CodeIgniter\Config\Services::session()
11 SYSTEMPATH/Common.php(988): CodeIgniter\Config\BaseService::__callStatic('session', [])
12 VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php(689): session('user')
13 VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php(707): CodeIgniter\Shield\Authentication\Authenticators\Session->getSessionUserInfo()
14 VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php(394): CodeIgniter\Shield\Authentication\Authenticators\Session->getSessionKey('id')
15 VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php(378): CodeIgniter\Shield\Authentication\Authenticators\Session->checkUserState()
16 VENDORPATH/codeigniter4/shield/src/Auth.php(159): CodeIgniter\Shield\Authentication\Authenticators\Session->loggedIn()
17 VENDORPATH/codeigniter4/shield/src/Filters/ChainAuth.php(47): CodeIgniter\Shield\Auth->__call('loggedIn', [])
18 SYSTEMPATH/Filters/Filters.php(173): CodeIgniter\Shield\Filters\ChainAuth->before(Object(CodeIgniter\HTTP\IncomingRequest), null)
19 SYSTEMPATH/CodeIgniter.php(473): CodeIgniter\Filters\Filters->run('cronJobs/machineAlert', 'before')
20 SYSTEMPATH/CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
21 FCPATH/index.php(75): CodeIgniter\CodeIgniter->run()


  Unlocking the Potential of Web Sockets in Modern Web Development
Posted by: InsiteFX - 09-13-2023, 07:30 AM - No Replies

Unlocking the Potential of Web Sockets in Modern Web Development


Lightbulb $routes->match() behavior in 4.4.1
Posted by: joho - 09-13-2023, 02:31 AM - Replies (2)

Does $routes->match() behave differently in 4.4.x?

I have this, and it works for 4.3.x, but seemingly not for 4.4.1:

Code:
use CodeIgniter\Router\RouteCollection;
use App\Controllers\zAdmin;

$routes->setTranslateURIDashes(false);
$routes->set404Override();

$routes->get( '/', [zAdmin::class, 'index'] );

$routes->group( 'zadmin', static function( $routes ) {
    $routes->match( ['get','post'], 'fetchinfo', [zAdmin::class, 'ajax_fetch'] );
    $routes->match( ['get','post'], 'fetchrepoinfo', [zAdmin::class, 'ajax_fetch_repo'] );
    $routes->match( ['get','post'], 'fetchzampnews', [zAdmin::class, 'ajax_fetch_zamp_news'] );
    $routes->match( ['get','post'], 'tagzampnews', [zAdmin::class, 'ajax_tag_zamp_news'] );
    $routes->match( ['get'], 'zamprepo', [zAdmin::class, 'zamprepo'] );
    $routes->match( ['get'], 'zampnews', [zAdmin::class, 'zampnews'] );
    $routes->match( ['get', 'post'], 'create', [zAdmin::class, 'edit'] );
    $routes->match( ['get', 'post'], 'edit/(:segment)', [zAdmin::class, 'edit'] );
    $routes->match( ['get'], '(:segment)', [zAdmin::class, 'view'] );
    $routes->get( '/', [zAdmin::class, 'index'] );
});

"Home" work, i.e. no parameters at all, but anything other than that yields a 404 with messages like "Can't find a route for 'get: 2'" (which I think should have been triggered on the second to last match(). I'm obviously doing something wrong, I just don't know what?


Hmm ... apparently this:

Code:
$routes->group( 'zadmin', static function( $routes )


needed to be this:

Code:
$routes->group( '', static function( $routes )


Question Nginx configuration with and without subdirectory
Posted by: joho - 09-13-2023, 12:36 AM - Replies (2)

Is there an nginx configuration equivalent of the supplied .htaccess file for CI4?

i.e. one that shows how to serve a CI4 application from a "root" URL and from a sub-directory URL.


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
enums in codeigniter 4 ?
by kenjis
2 minutes ago
Shield's autoloading perf...
by Muzikant
1 hour ago
Running unit tests in the...
by ableparsnips
2 hours ago
How can I integrate Faceb...
by growthstarboard
7 hours ago
Storing Error Logs in Dat...
by kenjis
11 hours ago
Shield: Set random user I...
by kenjis
Yesterday, 04:00 PM
What are those HTTP Respo...
by JustJohnQ
Yesterday, 10:14 AM
CodeIgniter ViteJs Plugin
by monster010
Yesterday, 09:23 AM
CodeIgniter Expenses - pe...
by ozornick
Yesterday, 08:55 AM
How to call function from...
by JustJohnQ
Yesterday, 07:30 AM

Forum Statistics
» Members: 66,716
» Latest member: rukiaong736
» Forum threads: 77,054
» Forum posts: 373,470

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB