Welcome Guest, Not a member yet? Register   Sign In
  external request for a file gives 404
Posted by: PaulC - Today, 01:06 AM - Replies (4)

Hi Team,
In our ci3 app we supply an external service with a web_url so they can take a copy of one of our files and analyse it before giving us a decision about its suitability for our site.
In ci4 I have used exactly the same idea but the 3rd party is saying they receive a 404 response so we are not getting good responses.
If I try to view the file in question by using the url I too get 404 but with a clue that the GET route is not defined.
eg https://www.mysite.com/images/uploads/te.../image.jpg
I have reviewed the routing docs and the smart file handling docs but am a bit mystified about how to enable this file to be retrieved externally.
I'm sure its easy but I cannot find the magic bullet ... yet.
Any clues appreciated, thx Paul


  Route passing $1 into the controller function instead of the value
Posted by: Alex.Fry - Today, 12:09 AM - Replies (5)

Hi team,
I have a new issue that is confusing me 
Using CodeIgnighter4, I have routes set up :
$routes->get("Entry/(:any)",'Home::Entry/$1');
$routes->get("LoadEvents/(:any)",'Home::Load_Events/$l/$2');

In the Controller:
    public function Entry($Hive_ID,$Entry_ID){ blah blah....}
    public function Load_Events($BeeKeeper_ID,$mth){
        echo "$BeeKeeper_ID<br>";
        echo "$mth<br>";


The Entry route works without issue... (tested from the application and from postman)
The Load_Events route echoes $1 as $BeeKeeper and nothing for $mth

Can anyone shed some light on this behaviour ? 

I have tried 
$routes->get("LoadEvents/(:any)",'Home::Load_Events/$l'); 
$routes->get("LoadEvents/(:any)/(:any)",'Home::Load_Events/$l/$2');
as well to no avail...


Any assistance will be appreciated.


  forge->addColumn
Posted by: Chroma - Yesterday, 10:24 AM - Replies (2)

Hi All,

CI 4.6.1.

I am trying to add a new column to an existing table. I am not having any luck.


PHP Code:
        $val                  = array();
        $obj['email_private'] = $this->getEmailField();
        $val                  $obj['email_private'] + ['after' => 'email_public'];
        $this->forge->addColumn('entry_requests'$val); 


getEmailFields looks like


PHP Code:
    protected function getEmailField()
    {
        $str = ['type' => 'VARCHAR''constraint' => '128''DEFAULT' => ' ''null' => 'false',];
        return $str;
    // end of method 

The error I am getting is an exception inside forge->addField. It seems that for some reason, it doesn't like the VARCHAR part of the definition. It throws a "Field information is required for that operation." exception, from line 387.

The variable $val contains:
  • type = "VARCHAR"
  • constraint = "128"
  • DEFAULT = " "
  • null = "false"
  • after = "email_public"

I don't see what I have done wrong and cannot find the error on the internet to track it down further.

Any help is much appreciated.


  Validation Rules: Valid email, but allow null?
Posted by: sevmusic - 05-19-2025, 02:05 PM - Replies (3)

In my app I have 2 email address fields.

The first field is required because it's the main account.

The second field is optional.

Here are my rules currently.

PHP Code:
public $profile = [
    
'login_email' => ['label' => 'Login Email''rules' => 'required|valid_email'],
    
'login_email_2' => ['label' => '2nd Login Email''rules' => 'valid_email'
]; 

But when I leave the login_email_2 field blank it complains that it's not a valid email.

How can I ignore the valid email rule if the field is blank?

I think I solved my own problem with permit_empty

Is there a listing of all the codeigniter validation rules?

I didn't see them singled out in the docs.


  Changing Session cookie - samesite v4.6.1
Posted by: codeus - 05-17-2025, 01:07 AM - Replies (12)

Hi all,
Using v4.6.1 - in app/Config/Cookie.php - after changing samesite setting to 'None'

PHP Code:
    public string $samesite 'None'

Console error is:
Quote:Cookie “pm_id” has been rejected because it is in a cross-site context ...

Still get cross-site errors. I'm doing this for testing, connecting to the remote CI4 server from localhost on local machine.

I've tried using Cookie helper to no avail-:
PHP Code:
helper('cookie');
 
set_cookie('session_id'''3600'',''truetrue'None'); 

Is it possible to force samesite to 'None' for the CI session cookie?

Many thanks,
Mike


  using app/Config/App.php in CodeIgniter 4
Posted by: sam547 - 05-16-2025, 03:04 PM - No Replies

Hello folks,
Does anyone know that if I put some codes in app/Config/App.php

PHP Code:
public function __construct()
    {
 
parent::__construct();
 
$services = new Services();
 
$services->loadServices();
 
    
does this get called at every request or when apache is restarted ?

Thanks


  hot-reload side effects seem to be clobbering my app
Posted by: PaulC - 05-14-2025, 05:09 AM - Replies (10)

Hi Team,
I am slowly losing the will ...
I think the debug toolbar and tracing is very helpful but at the moment my app is not behaving as expected ie serving a login view when someone logs out after redirect.
Looking at the FF java console I see messages like this:

The connection to https://localhost/__hot-reload was interrupted while the page was loading. login line 37 > injectedScript:702:29
EventSource failed:
error { target: EventSource, isTrusted: true, srcElement: EventSource, currentTarget: EventSource, eventPhase: 2, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, … }
login line 37 > injectedScript:710:21
    onerror https://localhost/login line 37 > injectedScript:710
    (Async: EventHandlerNonNull)
    hotReloadConnect https://localhost/login line 37 > injectedScript:709
    setHotReloadState https://localhost/login line 37 > injectedScript:697
    init https://localhost/login line 37 > injectedScript:27
    onreadystatechange https://localhost/?debugbar:49
    (Async: EventHandlerNonNull)
    loadDoc https://localhost/?debugbar:14
    (Async: EventListener.handleEvent)
    <anonymous> https://localhost/?debugbar:1
This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”. login
XHRGET
https://localhost/?debugbar_time=1747223756.436512
[HTTP/1.1 200 OK 78ms]

XHRGET
https://localhost/__hot-reload


At this moment I am trying to redirect to "https//localhost/login" which I have successfully proved works when I initially login, but once I logout and redirect back to the same place I never see the login screen again.
I am very frustrated and really cannot work out why.
Any help would be appreciated, Thx, Paul


Bug Missing closing bracket when there is cached query & multiple nested bracket
Posted by: abf - 05-13-2025, 07:27 PM - No Replies

There is an issue where 'closing bracket' does not appear when there is 'cached query' and 'multiple nested brackets'.

Here is the example code:

PHP Code:
// cached query
$this->db->start_cache();
$this->db->where("col_desc"'test_inside_bracket');
$this->db->stop_cache();

// add additional 'where' using bracket (used to implement 'keyset pagination')
$this->db->bracket();
    $this->db->bracket();
        $this->db->where("col_name > 'test_name'");
    $this->db->bracket_close();
    $this->db->or_bracket();
        $this->db->where("col_name = 'test_name'");
        $this->db->where("col_id < 12345");
    $this->db->bracket_close();
$this->db->bracket_close();
$this->db->order_by("col_name asc, col_id desc");

// check the query
$check_query $this->db->_get_select();
die(
$check_query); 

---
The result from code above is:
Code:
SELECT *
WHERE col_desc = 'test_inside_bracket'
AND  (
  (
col_name > 'test_name'
  )
OR    (
col_name = 'test_name'
AND col_id < 12345
)
ORDER BY col_name asc, col_id desc

The above result is missing 1 closing bracket.
The expected output should be like this:
Code:
SELECT *
WHERE col_desc = 'test_inside_bracket'
AND  (
  (
col_name > 'test_name'
  )
OR    (
col_name = 'test_name'
AND col_id < 12345
)
)
ORDER BY col_name asc, col_id desc

---
The issue above is gone when I remove the start_cache() and stop_cache() line (or one of those).
PHP Code:
// no cache, just plain where and some brackets
$this->db->where("col_desc"'test_inside_bracket');
$this->db->bracket();
    $this->db->bracket();
        $this->db->where("col_name > 'test_name'");
    $this->db->bracket_close();
    $this->db->or_bracket();
        $this->db->where("col_name = 'test_name'");
        $this->db->where("col_id < 12345");
    $this->db->bracket_close();
$this->db->bracket_close();
$this->db->order_by("col_name asc, col_id desc");

// check the query
$check_query $this->db->_get_select();
die(
$check_query); 

And the issue above is also gone when there is only one nested bracket:
PHP Code:
// cached query
$this->db->start_cache();
$this->db->where("col_desc"'test_inside_bracket');
$this->db->stop_cache();

// add additional 'where' using bracket (used to implement 'keyset pagination')
$this->db->bracket();
    $this->db->bracket();
        $this->db->where("col_name > 'test_name'");
    $this->db->bracket_close();
    // $this->db->or_bracket(); // if this bracket (and closing bracket) is uncommented, the closing bracket will be missing
    //    $this->db->where("col_name = 'test_name'");
    //    $this->db->where("col_id < 12345");
    // $this->db->bracket_close();
$this->db->bracket_close();
$this->db->order_by("col_name asc, col_id desc");

// check the query
$check_query $this->db->_get_select();
die(
$check_query); 

---
Please help with the issue above.
Any feedback / workaround would be greatly appreciated.
Thank you.

NB:
Temporary solusion for that issue is doing 'cache query' manually (put the query in function, then call that function to get the query. Not using start_cache()).


  Setting baseURL in Registrar not working
Posted by: petewulf1 - 05-13-2025, 03:20 AM - Replies (9)

Hey guys,
the registrar does not seem to work (at least for me). I followed th documentation and set it up like so:
-------------------

Code:
<?php

namespace Config;

class Registrar{

  public function __construct(){
    defined('LOCATION') || define('LOCATION', $_SERVER['CI_ENVIRONMENT']);
    }

  public static function App(): array{
     
    $conf = [];
    $conf['baseURL'] = 'http://192.168.0.1:81/'; 
    if(LOCATION == 'staging') $conf['baseURL'] = 'http://mydomain.com/';

    return $conf;

    }
  }
---------------------

I always get the error 
Fatal error: Uncaught CodeIgniter\Exceptions\ConfigException: Config\App::$baseURL "/" is not a valid URL. in ...\vendor\codeigniter4\framework\system\HTTP\SiteURI.php:201

Autodiscovery is set to true.
Its only workig if a manually set the baseURL in App.php but the URL should be set dynamically based on the environment. CI3 was way more comfortable and dynamic to set up.
Anybody knows the problem?

Thanks and kind regards,
Daniel


  Sessions old files are deleted
Posted by: Stord1980 - 05-11-2025, 11:31 PM - Replies (1)

Currently, within the Session library when using file - we see CI_Session_files_driver::read taking up to 120s to process 
Sessions old files are deleted but after some time I see still see these performance issues on requests tracked in NewRelic where it takes 100-120s


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

Username
  

Password
  





Latest Threads
Route passing $1 into the...
by davis.lasis
1 minute ago
external request for a fi...
by PaulC
Today, 11:19 AM
Validation Rules: Valid e...
by sevmusic
Today, 08:48 AM
forge->addColumn
by Chroma
Today, 12:54 AM
Setting baseURL in Regist...
by michalsn
Today, 12:10 AM
hot-reload side effects s...
by InsiteFX
05-20-2025, 10:13 PM
Changing Session cookie -...
by codeus
05-20-2025, 06:16 AM
Installation CI4 - Clonin...
by Arish12
05-20-2025, 02:19 AM
which linter to use (and ...
by paulbalandan
05-19-2025, 10:06 AM
Update from 4.6.0 to 4.6....
by Vespa
05-18-2025, 01:17 AM

Forum Statistics
» Members: 147,617
» Latest member: 88clbio1
» Forum threads: 78,395
» Forum posts: 379,502

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB