Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14353 articles
Browse latest View live

CodeIgniter Relations

$
0
0
I want to share a small project called CodeIgniter Relations. It adds support for rich model relations such as HasOne, HasMany, BelongsTo, BelongsToMany, including polymorphic and through relations, while staying fully based on CodeIgniter 4 models and entities.

The package supports eager and lazy loading to avoid N+1 queries, lets you save related data directly through relations, and relies on conventions to keep configuration minimal.

You may remember (or not) my similar project. This is the next version - better designed and with more options.

GitHub: https://github.com/michalsn/codeigniter-relations

Docs: https://michalsn.github.io/codeigniter-relations/

How to correctly do this using MVC?

$
0
0
Hello,
I have three tables: users, categories, and user_categories, along with two models for Users and Categories. Where should I implement the function to retrieve a user's categories? Should I create a third model called user_categories? What’s the best approach for accessing user categories?
Thanks in advance!

I built an app in every frontend framework

Cookie Partitioned

$
0
0
Will there be some parameter in the setCookie() function to be able to serve it as Partitioned or does it have to be managed manually?

My login feature cant proceed to the dashboard

$
0
0
Hi dearest developers,
I'm new to CI4, version 4.6.4, currently want to build a system with login with session and proceed to a dashboard. However, after inputing correct credential, the system didnt let me proceed to my dashboard. I had checked in the DevTools on chrome to check whether a cookie session is appear, and it does. Currently i had out of any idea on how to fix this. Does this issue might deal with any .htaccess or Config/App.php, or any other files?

your reply would be very valued for me. thank you for your time!

How to get customers who only bought two specific products?

$
0
0
Hello,
I made a query to get desired result but i am getting multiple customers not according requirements.
Code:
$builderObj = $this->db->table('customers');
$builderObj->join('orders', 'customers.id = orders.customer_id', 'left');
$builderObj->join('order_products', 'orders.id = order_products.order_id', 'left');
$builderObj->join('order_packages', 'orders.id = order_packages.order_id', 'left');
$builderObj->join('order_package_products', 'order_packages.id = order_package_products.order_package_id', 'left');
$builderObj->select('customers.id, customers.email');
$builderObj->where('customers.deleted_at', null);
$builderObj->where('orders.deleted_at', null);
$builderObj->havingGroupStart()
    ->having('COUNT(DISTINCT(order_products.product_id))', 1)
    ->orHaving('COUNT(DISTINCT(order_products.product_id))', 2)
    ->orHaving('COUNT(DISTINCT(order_package_products.product_id))', 1)
    ->orHaving('COUNT(DISTINCT(order_package_products.product_id))', 2)
->havingGroupEnd();
$builderObj->whereNotIn('orders.order_process_status_id', [OrderProcessStatusModel::PAYMENT_PENDING, OrderProcessStatusModel::ORDER_CANCELLED]);
$builderObj->groupBy('customers.id');
$builderObj->orderBy('customers.id', 'DESC');
$removeRestoreCustomersArr = $builderObj->get()->getResult('array');
return $removeRestoreCustomersArr;

CodeIgniter 4 and External Functions

$
0
0
Our application was built using CodeIgniter 3 and I'm in the process of trying to update it to CodeIgniter 4.6.3, however I'm encountering an issue where external functions don't seem to be getting called. The application being used is called MapGuide OpenSource (MGOS) and it has a series of functions that should be accessible to CodeIgniter, via an extension enabled in php.ini. The functions are successfully called in CodeIgniter 3.1.13, however I'm getting an error with CodeIgniter 4.6.3.
The MGOS developer provided a "sanity check" script that would determine if the functions are being called. Unfortunately, once the script gets to the external functions, it fails.

The beginning of script is:

echo "Initializing web tier";
try {
    MgInitializeWebTier("DIR_PATH\Web\www\webconfig.ini");\
} catch (MgException $initEx) {
    echo "Init failure!";
    die;
} catch (Exception $ex) {
    echo "[php]: Exception: " . $ex->getMessage() . "\n";
    die;
}
echo "[php]: Initialized\n";
// We haven't and shouldn't need to require/include constants.php
// they are now baked into the PHP extension along with the other
// MapGuide API proxy classes
echo "[php]: Testing some constants\n";

The next line is where it fails:

echo "  - " . MgMimeType::Agf . "\n";

The error CodeIgniter's returning is:

Class "App\Controllers\Maptools\MgMimeType" not found

Has anyone encountered an issue where CodeIgniter 4 won't recognize/call external functions? Any assistance would be greatly appreciated.

DEV - Websockets with Socket.IO


path to font-face inside CSS file

$
0
0
I'm using MAMP for various projects (not all use CI) but for this project I have:

PHP Code:
http://localhost:8080/newsite 

I've got the following folder structure:

PHP Code:
public
  style.css
  
fonts
      
HalisGR-Book-webfont.woff2
      
etc... 

I've got various font-face rules in my CSS file like

Code:
@font-face {
    font-family: "Halis Grotesque";
    src: url("fonts/HalisGR-Book-webfont.woff2") format("woff2"),
        url("fonts/HalisGR-Book-webfont.woff") format("woff"),
        url("fonts/HalisGR-Book.otf") format("opentype");
}

However they aren't linked so in the browser dev tools console there are lots of errors of the form:

Code:
GET http://localhost:8080/fonts/HalisGR-Bold-webfont.woff - Not found

It appears that the URLs in the CSS file are being treated as being from the server root rather than from the location of the CSS file. I'm not using SASS or other preprocessor so how do I make it that the URLs are relative rather than fixed? I've tried prepending "newsite/public/" but that doesn't work.

Typical!

A minute after posting I checked the base_url in Config/App.php

PHP Code:
public string $baseURL 'http://localhost:8080/'

Changed to

PHP Code:
public string $baseURL 'http://localhost:8080/newsite/'


And all works. Smile

It's two years since I last set up a project with CI so I've forgotten lots of the ins and outs.

Whats wrong?

$
0
0
Unable to connect to your database server using the provided settings.
Filename: core/CodeIgniter.php
Line Number: 518

As Oracle loses interest in MySQL, devs mull future options

The most reasonable way to convert CI3 SQL operations into CI4

$
0
0
I am upgrading a CI3 web shop into CI 4.1.8. The project contains many massive SQL queries, in this style (but so that the query can fill 10 or 20 screens):

$query = "SELECT Tablename.Id, Tablename.Product WHERE Tablename.Code = {$code} WHERE Tablename.Code = {$code}";
if ($prod != null) {
$query .= " AND Tablename.Product = {$prod}";
}
$res = $this->db->query($query)->result();

Considering that we are talking about quite massive amounts of SQL code, so it really makes a difference if the working strategy is simple vs. complex for the person who is doing the migration, what would be the most reasonable, not very labour-intensive way to convert CI3 Model functions of this style into CI4?

Note also my CI4 version, 4.1.8, which does not yet support CI4 Raw SQL methods.

Column name with space broken in two in CI4

$
0
0
I can find some (surprisingly few) discussions about this problem with Google, but nothing that actually explains a solution to the problem.

I am using CI 4.1.8.

My code contains this row:

$queryBuilder->where('i.`Manufacturer Code`', $company);

It causes an SQL error, and prtinting the query without executing it shows what has happened:

WHERE `i`.`Manufacturer` `Code` = 'Company Ltd'

What can I do to fix this problem?

This does not work either:

$queryBuilder->where('Manufacturer Code', $company);

it results in:

WHERE `Manufacturer` `Code` = 'Company Ltd'

: Integrating TikTok APIs with a CodeIgniter Project – Best Practices?

$
0
0
Hi everyone,
I’m currently working on a web application built with CodeIgniter, and I’m exploring ways to integrate TikTok features, like fetching user videos, displaying feeds, or even handling basic analytics through their API. I’m a bit new to working with TikTok’s developer tools and want to make sure I approach this the right way.
Has anyone here had experience connecting CodeIgniter projects with TikTok’s APIs? What challenges did you face with authentication, rate limits, or data handling? I’m especially curious about any recommended libraries, workflow tips, or common pitfalls to avoid.
Would love to hear your thoughts and real-world experiences so I can plan my integration more effectively!

Intergrating WhatsApp API in CI4 Application

$
0
0
Hi
What is the most common library that is being used for the WhatsApp API?
Thanks

Snowflake - Generative AI and LLMs for Dummies

jQuery 4.0.0 Has been released

Trouble inserting a row with spaces in column names

$
0
0
I am using CodeIgniter 4.1.8.

When I try to insert data into the primary table of a Model, columns with spaces in column names end up with null values. I have tried with and without ` quotes around the column name. Is there any way to make this work?

$data = array('Name' => 'My Name', 'Customer No' => '4442', 'Phone No' => '012345001');
$this->insert($data);

SELECT * FROM my_table;
1, 'My Name', NULL, NULL

$data = array('Name' => 'Her Name', '`Customer No`' => '4443', '`Phone No`' => '012345002');
$this->insert($data);

SELECT * FROM my_table;
1, 'My Name', NULL, NULL
2, 'Her Name', NULL, NULL

I have found ways to SELECT data with spaces in column names.

Spaces in table names became a problem in JOIN statements of QueryBuilder, though not in WHERE statements. I never found out how to make JOIN statements function with spaces in table names.

Digital Ocean blocks SMTP ports, how to send gmail?

$
0
0
I've been moving some little CI4 websites off of AWS servers (expensive, want to deny the tech behemoth my money) and I decided I'd try digital ocean. I'm starting to think this was a mistake. Digital Ocean blocks outgoing smtp requests from their virtual servers, aka "droplets." I've asked them to open this port and they've refused.

That being the case, I can't use the CI4 smtp mail client. I've been looking into the Gmail API but the gmail-api-php-client composer package is like 180MB -- literallly 4 MILLION lines of PHP code. They say there's a way to configure it to remove unused services but even then it apparently requires 1MB of code -- just to send an email!

I'm thinking I might try and throw together some code for sending email messages via Gmail API but I was wondering if anybody else is using an API to send outgoing email from CodeIgniter 4 and what approach they might be using.

Session variables not being set

$
0
0
When a user logs into my application, there should be an array of variables that are added to the Session parameter. This worked as expected in CodeIgniter 3, however it doesn't work in CodeIgniter 4. I've reviewed the documentation and it appears that everything is done correctly. Based on the following code, is there anything I'm missing? Has anyone encountered this before?

<?php
namespace App\Controllers\Login;

use CodeIgniter\Controller;
use App\Controllers\BaseController;
use App\Models\Admin\Users;
use App\Models\Admin\UserLog;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\Session\Session;
use App\Libraries\adLDAP;
use Exception;
use CodeIgniter\Config\Services;
use App\Libraries;

class Login extends BaseController {
    public function __construct() {
       helper('form','base_url');
    }

function _setEnvironment( $lan_id, $demoMode ) {
    $this->Users = new Users('Users');
        if ( $demoMode == 1 ) {
            $lan_id = 'Demo.User'; //Set the ID to Demo.User which is the User for Demo Mode
        }
        $uprefs = $this->Users->User_preferences( $lan_id );
        foreach ( $uprefs as $pref ) {
            switch ( $pref->PREFERENCE ) {
                case 'Language':
                    $lang = $pref->SETTING;
                    break;
                case 'Something Else':
                    $somethingElse = $pref->SETTING;
                    break;
            }
        }
        $indexpage = config('App')->indexPage;
        $email = $this->Users->Get_lanid( $lan_id )[0]->EMAIL;
        $uid = $this->Users->Get_lanid( $lan_id )[0]->ID;
        $query = $this->Users->User_roles( $uid );
        foreach ( $query as $row ) {
            $mapID = $row->MAP;
        }

        $session_dat = array( 'uid' => $lan_id, 'lang' => $lang, 'logged_in' => TRUE, 'demo' => $demoMode, 'mapid' => $mapID, 'sessionid' => '', 'indexpage' => $indexpage, 'usermail' => $email );
       //append the above array to the session parameter
        $session = session()
       $session->set( $session_dat );
       //write out the Session parameter to see if the new variables have been added
        var_dump(session());exit();
        return;
    }
?>
Viewing all 14353 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>