Welcome Guest, Not a member yet? Register   Sign In
  DateTime field validation
Posted by: serialkiller - 03-18-2025, 03:58 AM - Replies (2)

I'm trying to validate a dateTime field but I can't get it to work, is this not possible or am I doing something wrong?

PHP Code:
'myDateTime' => 'required|valid_date["Y-m-d H:i"]'


  RSS with CI 4.6
Posted by: cb21 - 03-17-2025, 11:25 AM - Replies (6)

Where can I find a simple example of RSS creation with CodeIgniter 4.6 I found example but it does not work cause old version. We should remove all 10 years old answers it is useless today


  Using a third party library without composer
Posted by: occitan - 03-17-2025, 01:48 AM - Replies (3)

I would like to use this library in a controller but without installing it with composer. How do i go about that?
https://github.com/MaestroError/php-heic-to-jpg
Where do I put the library and how do I properly namespace it?


Does this look correct?

require APPPATH . 'ThirdParty/HeicToJpg/src/HeicToJpg.php';
use Maestroerror\HeicToJpg;


  CodeIgniter France
Posted by: ALTITUDE_DEV - 03-17-2025, 01:32 AM - Replies (4)

Hello everyone!
After nearly five years of using CodeIgniter, creating my own CMS that now powers 14 French companies, and recently partnering with two other French CodeIgniter 4 developers, I’ve noticed that CodeIgniter is not very popular in France due to a general lack of awareness.

To address this, I’ve taken the initiative to create CodeIgniter France, a completely free and open-source platform dedicated to promoting CodeIgniter. The site will feature updates on patches, tutorials (both blog and video), and insights into the advantages of CI 4 in 2025.

Here’s a first preview of the site! Of course, I’m open to working with the official CI team to add relevant links and further highlight CodeIgniter in France.

The goal of CI France is to bring together French-speaking developers, facilitate learning, and showcase official CI updates.
As a passionate developer who dedicates a significant part of my professional work to CI, I felt it was important to provide this resource to the francophone community and demonstrate CodeIgniter’s power and relevance worldwide.

On top of that, I’m incredibly excited about launching a YouTube channel to help both new and experienced developers learn how to use CodeIgniter 4! ?

Link : https://codeigniterfrance.com

Looking forward to your thoughts and feedback!
Best regards
Florian


  insertBatch Auto Split
Posted by: TakonSix - 03-15-2025, 03:45 AM - No Replies

Hello,
i use insertBatch with more than 20.000 data from a file. Sometimes there are same entrys with a unique key. Now i try to catch the duplicate entry error instead of an exception and errorpage, but it wont work the suggested way.
What i'll do:
Turn off DBDebug in Database.php (set to false)
and then

PHP Code:
try { 
$Model->insertBatch($data); 
}catch (
Exception $e){
echo 
$e->getMessage();

Doesnt work!

Next
PHP Code:
$Model->insertBatch($data);
if(
$Model->error()['message']>''){
                var_dump($Model->error()['message']);
            
Work with small amount of Data doesnt work with large Data!

As i see it inserts the Data till error, than some not and than the rest but doesnt give the error back.

Testscript:
PHP Code:
$data = [];
$data[] = ['name'=>'Hans','wert'=>1];
        for($i=0;$i<5000;$i++){
            $data[] = ['name'=>'Tom_1'.$i,'wert'=>1];
        }
        $data[] = ['name'=>'Hans','wert'=>1];
        for($i=0;$i<5000;$i++){
            $data[] = ['name'=>'Tom_2'.$i,'wert'=>1];
        

Name is the primary key!
After i have 9901 Entry without error.

What am i missing?

Best regards


Question CI4 Shield, Users, Groups, Permissions managment
Posted by: brianjamestorr - 03-12-2025, 12:07 PM - Replies (6)

Hi
I want to make an admin panel like Users managment ( list/add/edit/update/delete ) and same for Groups and Permissions. As i saw from Shield docs there is no solution for this, only assign groups and permission from Shield functions.

Shield\Config\AuthGroups config class

PHP Code:
public array $groups = [
    'superadmin' => [
        'title'      => 'Super Admin',
        'description' => 'Optional description of the group.',
    ],
]; 
same as permissions 
PHP Code:
public array $permissions = [
    'admin.access'        => 'Can access the sites admin area',
    'admin.settings'      => 'Can access the main site settings',
    'users.manage-admins' => 'Can manage other admins',
    'users.create'        => 'Can create new non-admin users',
    'users.edit'          => 'Can edit existing non-admin users',
    'users.delete'        => 'Can delete existing non-admin users',
    'beta.access'        => 'Can access beta-level features'
]; 
Barrier with this kind of groups and permission i get into is that i will have system for maange Employees, Vehicles, Users, WebsiteSettings, and many other controllers. So this means i would need to add each controller.method to the file and permissions, but i want to make this dynamic so lets say Admin can create groups and permissions and save in database.

Is that means if i don't use config based permission and groups i cannot use a Shield and hes functions to check if user have permission to access controller/method ?


  Wrong phpunit.xml.dist shipped?
Posted by: trunky - 03-11-2025, 04:02 PM - Replies (1)

Hi everyone,
I've checked Github and there is an updated phpunit.xml.dist from 2 month ago, but it still (or again) shows in line 5

PHP Code:
    bootstrap="system/Test/bootstrap.php" 
and this was fixed here https://github.com/codeigniter4/CodeIgniter4/pull/8785 and probably should read like
PHP Code:
bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php" 

Florian


  DB Connection::execute() - error handling
Posted by: codeus - 03-11-2025, 06:20 AM - No Replies

PHP Code:
    protected function execute(string $sql)
    {
        while ($this->connID->more_results()) {
            $this->connID->next_result();
            if ($res $this->connID->store_result()) {
                $res->free();
            }
        }

        try {
            return $this->connID->query($this->prepQuery($sql), $this->resultMode);
        } catch (mysqli_sql_exception $e) {
            log_message('error', (string) $e);
            if ($this->DBDebug) {
                throw new DatabaseException($e->getMessage(), $e->getCode(), $e);
            }
        }
        return false;
    
My issue is: when encountering a duplicate key error (1062), the exception is caught, but NOT re-thrown UNLESS using the DBDebug flag.

Using SQL's INSERT IGNORE, the exception is not thrown. But, there is no error code from $this->db->error(). The only way I can think to detect the duplicate to use a transaction, do a SELECT, if that fails then do an INSERT.

Looking at this code, to me the if ($this->DBDebug) condition looks plain wrong. It's an accident waiting to happen. Using DBDebug and an appropriate try/catch block in the user's code, all works fine and dandy. In production, the code aborts because there is no re-throw.

It would be interesting to know the rationale for the dual behaviour. execute() must be one of the most commonly used methods in the framework.

Apologies if this has already been covered elsewhere. If I get time I'd like to update the documentation, the duplicate key handling required does not appear to be covered.


  help w/testing: variables not passed to view in 4.5.4
Posted by: rramsey - 03-10-2025, 07:48 AM - Replies (2)

Hi,
I'm using 4.5.4 and I'm trying to set up some tests but I'm having a difficult time. This is the code from my controller:

Code:
    $data['is_new'] = $is_new;
    return view('my_body', $data);
Then in the view I have this:
PHP Code:
<?php

?>
  if ($is_new) {
    <?php
      
print "Welcome, new user.";
    ?>
  } else {
      print "Welcome back.";
  } 


In my test, which I pretty much copied from the docs:
PHP Code:
<?php
  
namespace app\Controllers;
  use CodeIgniter\Test\CIUnitTestCase;
  use CodeIgniter\Test\FeatureTestTrait;
  use CodeIgniter\Test\DatabaseTestTrait;
  use PHPUnit\Framework\Attributes\TestDox;

  class MyControllerFeaturesTest extends CIUnitTestCase
  
{
    use FeatureTestTrait;
    use DatabaseTestTrait;
    /**
    * setup and teardown run before and after
    * the _entire_ test case
    * setup and tearDown run _between_ tests
    */
    public static function setUpBeforeClass(): void
    
{
      parent::setUpBeforeClass();
    }
    public static function tearDownAfterClass(): void
    
{
      parent::tearDownAfterClass();
    }
    protected function setUp(): void
    
{
      parent::setUp(); // Do not forget

      helper('text');
    }
    protected function tearDown(): void {
      parent::tearDown();
    }

    #[TestDox('A new user should get a welcome')]
    public function testViewingResults(): void
    
{
      $response $this->get('/forum/loggedin/79435')
                        ->call();
      $response->assertSee('Welcome, new user');
    }
  



The error I'm getting is that $is_new is not defined in the view:
Code:
ErrorException: Undefined variable $is_new

The page actually works just fine, no errors at all. I can go to the url, see the appropriate message based on whether or not I'm a new user. 

Any ideas?


  Undefined function esc() in v4.5.8
Posted by: cadgiru - 03-10-2025, 02:14 AM - Replies (2)

with:

Code:
<title><?= esc($title ?? 'Default Title') ?></title>
get error after upgrading:
Code:
PHP Fatal error:  Uncaught Error: Call to undefined function esc() in /var/www/mvc/xa/app/Views/templates/xaHeader.php:7
Stack trace:
#0 {main}
  thrown in /var/www/mvc/xa/app/Views/templates/xaHeader.php on line 7
Any ideas why?


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

Username
  

Password
  





Latest Threads
AssetConnect - a powerful...
by maniaba
4 hours ago
twig and view cell
by foxbille
5 hours ago
Best Way to Implement Aff...
by InsiteFX
9 hours ago
The pipe operator in PHP ...
by InsiteFX
Yesterday, 04:18 PM
Heads up for users using ...
by FlavioSuar
Yesterday, 11:33 AM
Table (view class) Row ID
by grimpirate
07-03-2025, 11:22 PM
curl + response body
by michalsn
07-03-2025, 10:10 PM
Happy 4th Everyone
by InsiteFX
07-03-2025, 09:31 PM
AbuseIPDB Module
by InsiteFX
07-03-2025, 09:27 PM
tool bar not showing
by Luiz Marin
07-03-2025, 04:46 AM

Forum Statistics
» Members: 154,872
» Latest member: rishika00
» Forum threads: 78,441
» Forum posts: 379,731

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB