Welcome Guest, Not a member yet? Register   Sign In
  PHP 8.2.11. This is a bug fix release.
Posted by: InsiteFX - 09-29-2023, 02:08 AM - Replies (3)

PHP 8.2.11. This is a bug fix release.

  Headers not properly set with response->setContentType
Posted by: bgeneto - 09-28-2023, 05:55 AM - Replies (2)

Any ideas why setting headers like this doesn't work:


but using like this works?

header('Content-Type: text/event-stream')

I've build the following MWE running on a fresh install of CI4's appstarter: 

PHP Code:

namespace App\Controllers;


Headers extends Controller
    public function not_working(): void

// data to be sent
$data = [
'timestamp' => time()

// Send the SSE data to the client
echo "data: " json_encode($data) . "\n\n";


    public function working(): void
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('Access-Control-Allow-Origin: *');

// data to be sent
$data = [
'timestamp' => time()

// Send the SSE data to the client
echo "data: " json_encode($data) . "\n\n";


Routes are configured like this:

PHP Code:

use CodeIgniter\Router\RouteCollection;

 * @var RouteCollection $routes
You will notice that the response header of "/not-working" is "text/html; charset=UTF-8" instead of "text/stream-event", tested with Apache/2.4.56 (Win 11 and Debian 12) with or without nginx reverse proxy.
To my surprise, with LiteSpeed or OpenLiteSpeed server "/not-working" returns the correct headers  Huh
Any ideas why both "$this->response->setContentType('text/event-stream');" and "$this->response->setHeader('Content-Type', 'text/event-stream')?" does not in my controller?


  Session Flashdata Persisting Like Normal Session Data
Posted by: ltarrant - 09-28-2023, 05:41 AM - Replies (4)

I currently have an issue with Flashdata persisting and behaving like normal session data.
This occurs with direct use of Flash data like:

$session->setFlashdata('item', 'value');
As well HTTP response functions like:
return redirect()->back()->with('foo', 'message');

I am currently using PHP 8.1 and the DatabaseHandler Driver.

This has been working fine but I recently upgraded to from CI version 4.3.6 to 4.4.0.

I only just spotted this issue an assume its linked to the version change. More likely an error on my part manually changing bits as part of the upgrade or maybe missing something.

Has anyone else had any issues or can direct me to particular area of the upgrade changes I should look at more closely that might cause this issue?

  How to Think Like a Developer: The Art of Problem Solving
Posted by: InsiteFX - 09-27-2023, 06:03 AM - No Replies

How to Think Like a Developer: The Art of Problem Solving

  Changing the MySQL Timezone
Posted by: Roel - 09-27-2023, 04:51 AM - Replies (1)

Before in CodeIgniter 3 I used to change the MySQL timezone with a query inside MY_Controller.
Now in CodeIgniter 4 I'm doing the same in the BaseController:

PHP Code:
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
        // Do Not Edit This Line


        $utc_offset =  date('P');

        $db = \Config\Database::connect();
        $db->query('SET time_zone = "'$utc_offset .'"'); 

I double checked, and it's running the query okay.
However when I retrieve data from the database, the datetimes are still on mysql server timezone UTC.
Ofcourse I can converse every datetime I retrieve from the database in my PHP code, however I prefer not to do this, as it will require me to do this on many points.

Thank you,

I solved the issue, it seems if I use time or datetime in the data column type it does notchange it by timezone, only when using the timestamp column type.

  Creating a PHPUnit Unit Test with File Upload via POST Route Using HTTP Testing
Posted by: Corda - 09-27-2023, 02:07 AM - Replies (2)

Hello CodeIgniter community,

I hope this message finds you well. I'm currently working on a CodeIgniter 4 project and I'm looking to implement a PHPUnit unit test that involves making a POST request with file upload to a specific route in my application. I'm specifically interested in using CodeIgniter's HTTP Testing features to accomplish this.

Here's a breakdown of what I aim to achieve:

1. Simulate a POST request to a designated route.
2. Include the capability to upload a file as part of this POST request.
3. Perform assertions to verify that the route handles the file upload correctly.
4. I've been researching CodeIgniter's HTTP Testing documentation and PHPUnit, but I could use some guidance on structuring this particular test case. If anyone in the community has experience with creating such tests, I would greatly appreciate your insights and any code examples you can share.

Here are some specific questions I have:

1. How can I use CodeIgniter's HTTP Testing features to simulate a file upload in my PHPUnit test case?
2. What are the recommended assertions I should use to ensure that the file upload is handled correctly by the target route?
3. Are there any best practices or tips related to CodeIgniter 4 and HTTP Testing that I should keep in mind while setting up this test?

Having a clear understanding of how to create this unit test will be invaluable in enhancing the robustness of my application.

I'd like to express my gratitude in advance for any assistance and expertise you can provide.

Best regards

  Undefined method URI::siteUrl() after upgrading to 4.4.x
Posted by: DatDraggy - 09-26-2023, 07:18 AM - Replies (4)

Hey there,
I've been busy upgrading my CI4 instance from 4.2.0 to 4.4.1. All went smooth until the step up to 4.4.0.

redirect()->route() returns $this->redirect(site_url()) 

Inside the site_url helper func, $currentURI is set from Services::request()->getUri();. However, getUri returns an instance of URI instead of the expected SiteURI.
$currentUri->siteUrl() is returned, but siteUrl is only present in the previously mentioned SiteURI.
I've researched this a bit and saw an issue regarding this exact thing, however it only concerned CLI and the fix in dev doesn't help me.

Am I missing something? Hope someone can help me out here.

I'm using nginx with php7.4-fpm

  Pagination with Join queries
Posted by: udaopi - 09-26-2023, 01:32 AM - Replies (3)

Hello, i have problem in pagination.

im try to make manual pagination based on documentation, and get some help from ChatGPT, but that AI cannot fix it.

i can't get array key when using  select() and join() it with another table.

this is it,
my english not good, hope you all understand what i mean.

PHP Code:
public function berita() {
        $perPage 10;
// Membuat instance pager.
        $pager service('pager');
= (int) ($this->request->getGet('page') ?? 1);
->select('tb_berita.*, tb_foto.foto AS foto_berita, tb_katberita.nama AS kategori_berita')
            ->join('tb_foto''tb_foto.id_konten = tb_berita.id AND tb_foto.tabel = "tb_berita"''left'
            ->join('tb_kat_berita''tb_kat_berita.id = tb_berita.id_kat','left')
// Menghitung total data yang ada di tabel.
        $total $query->countAll();
$query->findAll($perPage$page $perPage $perPage);
foreach ($konten as &$beritaterbaru) {
            $beritaterbaru['nama_hari'] = $this->namaHari($beritaterbaru['hari']);
date('Y-m-d'strtotime('-1 year'));
        $beritapopuler $this->beritaModel->where('aktif''1')->where('tanggal >='$tahunTerakhir)->orderBy('hit''desc')->limit(6)->find();
foreach ($beritapopuler as &$databerita) {
            $databerita['nama_hari'] = $this->namaHari($databerita['hari']);
foreach ($pengumuman as &$datapengumuman) {
            $datapengumuman['nama_hari'] = $this->namaHari($datapengumuman['hari']);
foreach ($download as &$datadownload) {
            $datadownload['nama_hari'] = $this->namaHari($datadownload['hari']);
= [
            'konten' => $konten,
            'modul' => 'berita',
            'pager_links' => $pager_links,
            'kontak' => $this->kontakModel->where('id'1)->first(),
= [
            'beritapopuler' => $beritapopuler,
            'pengumuman' => $pengumuman,
            'download' => $download,
return view('themeopi/header'$data) .
            view('themeopi/content_category'$data2) .

i try to var_dump() the result $data['konten'], but 'foto_berita' and 'kategori_berita' not exist.
look at $query,  OrderBy not work too .
where the problem?

  Shield's autoloading performance
Posted by: Muzikant - 09-25-2023, 11:57 PM - Replies (5)

I am starting with Shield. After successful installation (Composer and Spark) I realized, that Auth helper is autoloaded everywhere. I need it only in admin panel, nowhere else. The documentation is saying, it is autoloaded by Composer.

  1. Is it possible to load Shield only where I want it?
  2. Does autoloading in Composer have impact on performance as level 1 optimization is enabled by default?

I realized, that Shield's dependency Settings library is always sending database request for settings table, even if I am not using neither the Shield or the Settings library. This behavior is unwanted for me. (Edit: It was my mistake. It is not doing this.)

CodeIgniter 3 and less was great, because it was not loading anything "for me" until I specifically asked for it. I know, Shield is not essential part of CI, but this behavior looks like Laravel style, which is leading to bloating software, which I really do not want and I am suspicious on CI too now as Lonnie is an active member of the community. I really hope CodeIgniter is not heading this way, because why should I use Laravel style framework, if I can use Laravel directly? And why should I use Shield, if it is doing stuff "for me", which I really do not want?

  Implement Shield authentication with Vue 3
Posted by: eleumas - 09-25-2023, 10:05 AM - Replies (5)

Hi! I'm building my first web app with Vue 3. I builded with Vue and Axios a CRUD and now i would like implement Shield authentication.
Do you have any suggestion for me? It is possible to do?
Thanks for help me.

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



Latest Threads
Storing Error Logs in Dat...
by kenjis
1 hour ago
Shield: Set random user I...
by kenjis
1 hour ago
Shield's autoloading perf...
by kenjis
1 hour ago
What are those HTTP Respo...
by JustJohnQ
7 hours ago
CodeIgniter ViteJs Plugin
by monster010
7 hours ago
CodeIgniter Expenses - pe...
by ozornick
8 hours ago
How to call function from...
by JustJohnQ
9 hours ago
Why controller under admi...
by kenjis
Today, 01:05 AM
Development of 4.5 is ong...
by kenjis
Yesterday, 08:30 PM
How do I Migrate from 4.3...
by kenjis
09-30-2023, 05:41 PM

Forum Statistics
» Members: 66,666
» Latest member: idialstars
» Forum threads: 77,054
» Forum posts: 373,464

Full Statistics

Search Forums

(Advanced Search)

Theme © iAndrew 2016 - Forum software by © MyBB