Welcome Guest, Not a member yet? Register   Sign In
  5 Things I Wish I Knew Before Starting a Startup as a Software Engineer
Posted by: php_rocs - 1 hour ago - No Replies

StartUp advice (DevTo): https://dev.to/code42cate/5-things-i-wis...ineer-208i


  Why Every Programmer Needs a Non Computer Hobby
Posted by: php_rocs - 1 hour ago - No Replies

Good advice ( DevTo): https://dev.to/mahdijazini/why-every-pro...-hobby-fgf


  Using Pager with an Array
Posted by: nneves - Yesterday, 01:55 PM - No Replies

Hi

I have some results from a Model that needs to be cached after being parsed to clean user comments.

Is there's a way to use Pager with an Array?

Thanks


  CodeIgniter 4.6.1 has been released
Posted by: InsiteFX - 05-03-2025, 03:01 AM - Replies (2)

CodeIgniter 4.6.1 has been released Download
Upgrading from 4.6.0 to 4.6.1
Changes
Bugs Fixed
I' am sorry to say that while I was cleaning up the SPAM this morning I Accidently deleted the thread.
Which I' am reporting to MyBB because the thread was not even checked a post was.
Again sorry for my mistake.

I have emailed Paul to let him know about it.


  Feature to not append database prefix in QueryBuilder
Posted by: objecttothis - 05-02-2025, 02:37 AM - Replies (5)

Currently I'm not aware of the means to prevent query builder from appending the database prefix, so which you need to run a query where you do not want the prefix appended, you either can't use QueryBuilder or you have to use acrobatics to make it work. Please consider adding a parameter to QueryBuilder turning off the appending of the database prefix.

Take this code as an example of what I mean

PHP Code:
function dropForeignKeyConstraints(array $foreignKeysstring $table): void {
    
$db Database::connect();

    
$prefixName $db->getPrefix();
    
$db->setPrefix('');
    
$database_name $db->database;

    foreach (
$foreignKeys as $fk)
    {
        
$builder $db->table('INFORMATION_SCHEMA.TABLE_CONSTRAINTS');
        
$builder->select('CONSTRAINT_NAME');
        
$builder->where('TABLE_SCHEMA'$database_name);
        
$builder->where('TABLE_NAME'$table);
        
$builder->where('CONSTRAINT_TYPE''FOREIGN KEY');
        
$builder->where('CONSTRAINT_NAME'$fk);
        
$query $builder->get();

        if(
$query->getNumRows() > 0)
        {
            
$db->query("ALTER TABLE `$table` DROP FOREIGN KEY `$fk`");
        }
    }

    
$db->setPrefix($prefixName);


To prevent the query builder from appending the dbPrefix to INFORMATION_SCHEMA.TABLE_CONSTRAINTS, which would break the query, I need to capture the prefix, set it to an empty string, then put it back after I'm done with the QueryBuilder so that code below resumes the prefix appending. While this isn't needed all the time, it's better if I don't pepper the code with these extra three lines. I could write $prefixName = removePrefix() and restorePrefix($prefixName) helper functions, but that really only saves me one line of code. It would be better if I could call something like $builder = $db->table('INFORMATION_SCHEMA.TABLE_CONSTRAINTS', false); where the false parameter in the table() function returned the query without the prefix appended.


  CI4 not loading after fresh install — blank page on localhost Post:
Posted by: sultanhassann6 - 04-30-2025, 01:13 AM - No Replies

I’m trying to set up CodeIgniter 4 on my local dev machine (Ubuntu 22.04, PHP 8.1) for a side project — a fresher job board I’m working on: https://247uaefreshers.com.
I followed the official CI4 install guide using Composer, no issues during setup. But when I navigate to

Code:
localhost:8080
, I just get a blank white page — no error, no logs, nothing in the browser console either.
I’ve tried:
• Running
Code:
php spark serve
(starts fine)
• Double-checked
Code:
.env
settings
• Permissions on writable/ seem okay
• Tried adding basic echo in
Code:
app/Controllers/Home.php
— still blank
Anyone seen this behavior before? Wondering if I missed something basic. Appreciate any tips ?


  Model Find function Changed?
Posted by: dulongc - 04-29-2025, 02:41 PM - Replies (1)

In the past when I used the find() function on a model while passing the primary key, I would get a single result as the documentation states. It seems now in v. 4.6.0 it acts like it is going to return multiple results. This requires me to call $returnedArray[0]['name'] instead of just $returnedArray[0]['name']

My Relevant Code:

PHP Code:
$transID $this->request->getPost('trans_id',FILTER_SANITIZE_NUMBER_INT);
$transModel = new \App\Models\TransactionModel();
$prevTran $transModel->find($transID);

//Make sure this payment intent isn't already paid
if($prevTran['status'] == 'paid') {
                    
    
//This transaction is already paid
    
echo json_encode(array('status'=>'alread_paid','message'=> 'This transaction is already marked as paid.'));
    exit();
                    



This results in error:
Quote:message 'Undefined array key "status"'

Upon inspecting the return from the database I can see the issue is that it's returning the row within a multidimensional array.

Expected Return:
Code:
$transModel = [
    'id'         => 1,
    'name'    => 'Registration',
    'status'    => 'paid',
]

Actual Return
Code:
$transModel = [
    [0]    =>    [
        'id'         => 1,
        'name'    => 'Registration',
        'status'    => 'paid',
    ],
]

I can do a work around by just overwriting the response. But am I wrong in believing this should already be the default response.

PHP Code:
$transID $this->request->getPost('trans_id',FILTER_SANITIZE_NUMBER_INT);
$transModel = new \App\Models\TransactionModel();
$prevTran $transModel->find($transID);

//Overwrite the return here
$prevTran $prevTran[0];

//Make sure this payment intent isn't already paid
if($prevTran['status'] == 'paid') {
                    
    
//This transaction is already paid
    
echo json_encode(array('status'=>'alread_paid','message'=> 'This transaction is already marked as paid.'));
    exit();
                    


  Option to translate uri to camel case
Posted by: massimiliano1.mancini - 04-29-2025, 10:37 AM - Replies (3)

Hi All,
I'm currently using improved auto-routing, so the option to convert URIs to camelCase caught my attention. It was introduced in version 4.5.0 and enabled by default starting from version 4.6.0. I had to disable it to avoid breaking my project's code, but I'm seriously considering refactoring the code to make use of it.
The documentation notes that "The option to disable 'Translate URI To CamelCase' exists only for backward compatibility. We don’t recommend to disable it." — but the reasons behind this recommendation aren't entirely clear to me.
Before diving headfirst into the refactor, I'd like to hear your thoughts on the pros and cons of enabling this option.
Thanks in advance for any suggestions, advice, and opinions!


  How use MATCH(action) AGAINST(?)
Posted by: motoroller - 04-28-2025, 02:46 PM - Replies (4)

How use MATCH(action) AGAINST(?) in Query Builder Class
i have found only like mode


  How to refer to 'session' in my code
Posted by: PaulC - 04-28-2025, 05:05 AM - Replies (4)

Hi Team,
Chugging my way through the 3->4 migration guide, I did as suggested and changed all my old $this->session calls to $session (and all the slightly different methods).
I then wondered how/where to initialise it as the superglobal is no more and v3 autoloading has been "improved".
Eventually I read about the BaseController and how to initialise stuff there.
However, the example in the forum (somewhere) suggests setting a private $session variable and then calling $this->session = \Config\Services:Confusedession(); in the constructor.
I think I now need to refer to the session object using $this->session.
So is is $session or $this->session?
I'm so bewildered.
cheers, Paul


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

Username
  

Password
  





Latest Threads
5 Things I Wish I Knew Be...
by php_rocs
1 hour ago
Why Every Programmer Need...
by php_rocs
1 hour ago
Using Pager with an Array
by nneves
Yesterday, 01:55 PM
Access of env-vars in Con...
by paulkd
Yesterday, 12:48 AM
Feature to not append dat...
by michalsn
05-03-2025, 01:21 PM
CodeIgniter 4.6.1 has bee...
by InsiteFX
05-03-2025, 11:41 AM
How use MATCH(action) AGA...
by WitER
05-01-2025, 03:46 AM
Option to translate uri t...
by massimiliano1.mancini
05-01-2025, 03:44 AM
Magic login link not work...
by taco_greco
04-30-2025, 02:41 AM
CI4 not loading after fre...
by sultanhassann6
04-30-2025, 01:13 AM

Forum Statistics
» Members: 144,048
» Latest member: urbaniatraveller
» Forum threads: 78,374
» Forum posts: 379,366

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB