Welcome Guest, Not a member yet? Register   Sign In
  Very high latency when connecting to database
Posted by: chastel - 04-14-2024, 11:28 AM - No Replies

Hi, I'm facing an issue where connecting to the database takes too much time. I'm using CodeIgniter 4 with Neon (PostgreSQL serverless) as the database. Additionally, I'm running this app behind a Cloudflare proxy. Anyone know why this is happening?

[Image: K6YboYmU_o.png][Image: K6YboYmU_o.png]


  Shield 1.0.3
Posted by: kenjis - 04-14-2024, 02:02 AM - Replies (1)

The bug fix 1.0.3 has been released!
It is compatible with CI v4.5.1.

See release note for details.

Shield is the official authentication and authorization framework for CodeIgniter 4.
See https://shield.codeigniter.com/


  v4.5.1 Bug Fix Released
Posted by: kenjis - 04-13-2024, 09:33 PM - Replies (2)

We have just released v4.5.1 bug fix.

This version fixed all reported bugs including TypeError in v4.5.0.
All v4.5.0 users should upgrade immediately.

Other CI4 users are encouraged to upgrade to v4.5.1 after detailed verification.

ChangeLog: https://codeigniter4.github.io/userguide...4.5.1.html
Upgrading Guide: https://codeigniter4.github.io/userguide...e_451.html

Note: Unfortunately now the User Guide on the official site is not yet updated due to the deployment trouble.

Important: There is a bug in appstarter v4.5.1. If you install appstarter, please fix the following path.

Code:
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -2,7 +2,7 @@
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
-    bootstrap="system/Test/bootstrap.php"
+    bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php"
    backupGlobals="false"
    beStrictAboutOutputDuringTests="true"
    colors="true"


  Array to HTML "Table"
Posted by: HarmW94 - 04-13-2024, 08:29 AM - Replies (3)

Hi,

Based on the data below, I want to create a list/table with the data that ends up in the array. However, I can't figure it out and I have tried everything regarding array format, count, etc.

I hope it's clear because I can't figure it out. As an example (from Excel);

Code:
Participants    Category
20              Boklam
12              Jeugbok
6               Jongerebok
9               Ouderebok
2               Veteranenbok

60              Geitlam
30              Jeugdgeit
20              Jongeregeit
15              Ouderegeit
5               Veteranengeit

This is my query (where $id = 24);

Code:
SELECT show_participants.*,
       zoo_easy.Gender,
       zoo_easy.Born,
       zoo_easy.Name,
       zoo_easy.OwnerName
FROM   show_participants,
       zoo_easy
WHERE  show_participants.participant_show = ' . $id . '
       AND show_participants.participant_animal = zoo_easy.RegistrationNumber
ORDER  BY zoo_easy.Gender,
          zoo_easy.Born DESC 




And this is the result I get from print_r;

Code:
Array
(
    [0] => Array
        (
            [participant_id] => 106
            [participant_animal] => A22035
            [participant_show] => 24
            [participant_category] => 4
            [Gender] => Bok
            [Born] => 2022-03-10
            [Name] => Abel van de Zwartberg
            [OwnerName] => B.  Segers Bert
        )

    [1] => Array
        (
            [participant_id] => 105
            [participant_animal] => NN24-195
            [participant_show] => 24
            [participant_category] => 2
            [Gender] => Geit
            [Born] => 2024-03-18
            [Name] => Pearl van de Pijpjes
            [OwnerName] => S.H.  Dekker
        )

    [2] => Array
        (
            [participant_id] => 104
            [participant_animal] => NN24-195
            [participant_show] => 24
            [participant_category] => 3
            [Gender] => Geit
            [Born] => 2024-03-18
            [Name] => Pearl van de Pijpjes
            [OwnerName] => S.H.  Dekker
        )

    [3] => Array
        (
            [participant_id] => 103
            [participant_animal] => A23001
            [participant_show] => 24
            [participant_category] => 2
            [Gender] => Geit
            [Born] => 2023-01-01
            [Name] => Mit van het Heieinde
            [OwnerName] => B.  Van den Broeck Ben
        )

)

This is the helper that's calculates the Category for me;

PHP Code:
<?php
use App\Models\CategoriesModel;
use 
CodeIgniter\CodeIgniter;

function 
getCategory($data)
{
    $categoriesModel = new CategoriesModel();

    $gender $data['Gender'];

    $born substr($data['Born'], ,4);
    $year date("Y");
    $count date("Y") - substr($data['Born'], ,4);

    // Lam
    if ($count == 0)
    {
        $sql $categoriesModel->getCategoryData('1');
        $result $gender strtolower($sql['category_name']);
    }

    // Jeugd
    if ($count == 1)
    {
        $sql $categoriesModel->getCategoryData('2');
        $result $sql['category_name'] . strtolower($gender);
    }

    // Jongere
    if ($count == 2)
    {
        $sql $categoriesModel->getCategoryData('3');
        $result $sql['category_name'] . strtolower($gender);
    }

    // Oudere
    if ($count == OR $count == OR $count == 5)
    {
        $sql $categoriesModel->getCategoryData('4');
        $result $sql['category_name'] . strtolower($gender);
    }

    // Veteraan
    if ($count >= 6)
    {
        $sql $categoriesModel->getCategoryData('5');
        $result $sql['category_name'] . strtolower($gender);
    }

    // Error handling
    if (empty($result))
    {
        $result 'Onjuiste data';
    }

    return $result;


I hope someone can help me, because I've been stuck on this for several days now and running out of time. I can't and do not want to change anything in the zoo_easy table. This is loaded using a CSV file because it comes from a different system.

Cheers.


  Filter Issue for version 4.5.0
Posted by: nghaka - 04-13-2024, 01:06 AM - Replies (1)

Hello,
I have a filter issue in version 4.5.0. It is working fine in version 4.4.8, but as soon as I upgraded to version 4.5.0, the following errors came up.

TypeError
str_contains(): Argument #1 ($haystack) must be of type string, null given


SYSTEMPATH\Debug\Toolbar.php at line 436

429 . 'data-time="' . $time . '" '
430 . 'src="' . site_url() . '?debugbar"></script>'
431 . '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
432 . '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
433 . $kintScript
434 . PHP_EOL;
435
436 if (str_contains($response->getBody(), '<head>')) {
437 $response->setBody(
438 preg_replace(
439 '/<head>/',
440 '<head>' . $script,
441 $response->getBody(),
442 1
443 )


My CIFilter Code is as follows:

Code:
public function before(RequestInterface $request, $arguments = null)
    {
        if( $arguments[0] == 'guest'){
            if( CIAuth::check()){
                return redirect()->route('admin.home');
            }            
        }

        if( $arguments[0] == 'auth'){
            if( !CIAuth::check()){
                return redirect()->route('admin.login.form')->with('fail', 'You must be logged in first.');
            }
        }
    }

And also my route code is as follows:

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

    $routes->group('',['filter'=>'cifilter:auth'], static function($routes){
        
        $routes->get('home','AdminController::index',['as'=>'admin.home']);
        $routes->get('logout','AdminController::logoutHandler',['as'=>'admin.logout']);
    });

    $routes->group('',['filter'=>'cifilter:guest'], static function($routes){
      
        $routes->get('login','AuthController::loginForm',['as'=>'admin.login.form']);
        $routes->post('login','AuthController::loginHandler',['as'=>'admin.login.handler']);
    });
});


  How to Test CI4 under Development
Posted by: kenjis - 04-12-2024, 06:18 PM - No Replies

You can test develop branch while waiting for the new patch release.
https://codeigniter.com/user_guide/insta...latest-dev
and help us give more feedback in case of any regression.

Also, you can test the next Minor Version branch like 4.6.
https://codeigniter.com/user_guide/insta...or-version


  Pagination with group by return oci_execute(): ORA-00979: not a GROUP BY expression
Posted by: just - 04-12-2024, 01:31 PM - Replies (5)


        return $this;

Code:
$this->builder()
            ->select(‘name, address’)
            ->selectSum('TOTAL’)
            ->groupBy(‘name’, ‘address')
            ->limit($limit,  $offset);

        return $this;


Hi, im new to this forum, i tried to make pagination,  everything work without group by.  
can i get some help?

im using 4.4.6 version.


  Suggestions for open-source applications using SQLite as a database
Posted by: tarcisiodev1 - 04-12-2024, 11:52 AM - No Replies

Hello everyone, I'm interested in exploring open-source projects that utilize SQLite as a database. Could you please recommend some interesting applications that I can study and contribute to? I appreciate any suggestions in advance!


Question Unable to connect to the database. Using Postgre Driver
Posted by: warcooft - 04-12-2024, 10:12 AM - Replies (1)

I have followed the documentation regarding database configuration. https://codeigniter.com/user_guide/datab...tion.html#

here my db config:

PHP Code:
public array $default = [
        'DSN'          => 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=1',
        'hostname'    => 'localhost',
        'username'    => 'postgres',
        'password'    => '123456',
        'database'    => 'playground_db',
        'DBDriver'    => 'Postgre',
        'DBPrefix'    => '',
        'pConnect'    => false,
        'DBDebug'      => true,
        'charset'      => 'utf8mb4',
        'DBCollat'    => 'utf8mb4_general_ci',
        'swapPre'      => '',
        'encrypt'      => false,
        'compress'    => false,
        'strictOn'    => false,
        'failover'    => [],
        'port'        => 5432,
        'numberNative' => false,
        'dateFormat'  => [
            'date'    => 'Y-m-d',
            'datetime' => 'Y-m-d H:i:s',
            'time'    => 'H:i:s',
        ],
    ];

  

and then i got this error:

Unable to connect to the database.
Main connection [Postgre]: pg_connect(): Unable to connect to PostgreSQL server: invalid sslmode value: &quot;1&quot;

Here details:
https://postimg.cc/bGf6Kmfw

I have applied the above configuration to the .env file in Codeigniter 4.4.8 and it works fine, but why doesn't it work in Codeigniter 4.5.0? Previously I tried to apply it in .env exactly with version 4.4.8 but it didn't work. Lastly, I configured it in the Config\Database.php file and it also didn't work.


  Best practice/how to deal with CORS
Posted by: Willen - 04-12-2024, 06:06 AM - Replies (1)

Hello! 

I have had a project that have been running Codeigniter 3 for a long time and now I'm on a journey to convert it to Codeigniter 4.

I have a separate front end and I'm using Codeigniter as an api. When I tested my endpoints in postman it was working fine, then when I tested it in browser I was getting multiple CORS-erros, like:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I read a bunch of threads on this forum and found one solution in this thread: https://forum.codeigniter.com/showthread.php?tid=80043 . The solution was to make a CORS-Filter and add options-routes for all my endpoints: https://gist.github.com/kenjis/e757d2b41...7e6eaa1254

Cors-filter:

Code:
<?php

declare(strict_types=1);

namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

class Cors implements FilterInterface
{
    /**
    * @param array|null $arguments
    *
    * @return RequestInterface|ResponseInterface|string|void
    */
    public function before(RequestInterface $request, $arguments = null)
    {
        /** @var ResponseInterface $response */
        $response = service('response');

        // Set your Origin.
        $response->setHeader('Access-Control-Allow-Origin', getenv('CORS_ORIGIN'));

        // Set this header if the client sends Cookies.
        // $response->setHeader('Access-Control-Allow-Credentials', 'true');

        if ($request->is('OPTIONS')) {
            $response->setStatusCode(204);

            // Set headers to allow.
            $response->setHeader(
                'Access-Control-Allow-Headers',
                'X-API-KEY, X-Requested-With, Content-Type, Accept, Authorization'
            );

            // Set methods to allow.
            $response->setHeader(
                'Access-Control-Allow-Methods',
                'GET, POST, OPTIONS, PUT, PATCH, DELETE'
            );

            // Set how many seconds the results of a preflight request can be cached.
            $response->setHeader('Access-Control-Max-Age', '3600');

            return $response;
        }
    }

    /**
    * @param array|null $arguments
    *
    * @return ResponseInterface|void
    */
    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
    }
}


Is this the best practice in dealing with cors preflights? Without the options route defined, I get CORS errors. Do I have to add options for all of my endpoints or am I missing something?

Code:
$routes->group('', ['filter' => 'cors'], static function (RouteCollection $routes): void {
  $routes->options('/auth/login', 'Auth::login');
  $routes->post('/auth/login', 'Auth::login');


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

Username
  

Password
  





Latest Threads
TypeError when trying to ...
by b126
4 hours ago
Retaining search variable...
by pchriley
4 hours ago
Reading a session variabl...
by xanabobana
5 hours ago
Update to v4.5.1, same us...
by kenjis
Yesterday, 07:47 PM
Codeigniter 4 extend core...
by Semsion
Yesterday, 05:08 AM
v4.5.1 Bug Fix Released
by lokman
04-16-2024, 02:12 PM
problem with textarea
by Nitin Arora
04-16-2024, 05:07 AM
Showing pdf on browser
by aarefi
04-16-2024, 04:38 AM
[4.5.1] Disabling the deb...
by keto
04-16-2024, 02:43 AM
directory structure
by badger
04-16-2024, 01:49 AM

Forum Statistics
» Members: 84,454
» Latest member: iplwincool
» Forum threads: 77,557
» Forum posts: 375,889

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB