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

using app/Config/App.php in CodeIgniter 4

$
0
0
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

Changing Session cookie - samesite v4.6.1

$
0
0
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

Validation Rules: Valid email, but allow null?

$
0
0
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.

forge->addColumn

$
0
0
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.

Route passing $1 into the controller function instead of the value

$
0
0
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.

external request for a file gives 404

$
0
0
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

How to Use CodeIgniter Global Functions (e.g., helper(), model()) Inside Custom "Mana

$
0
0
Hi everyone,
I'm working on a project where I'm using an MVCM (Model-View-Controller-Manager) pattern. Here's how I’ve structured it:
  • Model: Represents the database table.
  • Entity: Represents a single row of the table.
  • Manager: Contains the business logic that coordinates between models and entities.
  • Controller: Talks to the Manager, which then handles the lower-level details.
I've created a Managers directory inside app/ , and I intend for my controllers to interact only with Managers — not directly with Models or Entities.
The issue: inside the Manager classes, I’m unable to use common global functions like helper(), model(), etc., that work seamlessly in Controllers.

Question:
Is there a way to make these global CodeIgniter functions available inside my custom Managers classes, just like they are in Controllers?

Thanks in advance!

CI Shield setup: can't connect to database

$
0
0
I've run into a problem that is driving me nuts. I installed CI4.6.1 and everything went as expected. I need an authentication system, so I turned to CI Shield. Followed the docs and installation seemed to run smoothly. And that's when things went south: ran the setup through spark - everything worked until the last step and this got thrown at me:
Code:
Running all new migrations...
[CodeIgniter\Database\Exceptions\DatabaseException]
Unable to connect to the database.
Main connection [MySQLi]: No such file or directory
at SYSTEMPATH/Database/BaseConnection.php:467
I double checked my database config and everything seemed to be fine:

Code:
public local -> array (20) [
        'DSN' => string (0) ""
        'hostname' => string (9) "localhost"
        'username' => string (4) "root"
        'password' => string (4) "root"
        'database' => string (10) "benzaiten2"
        'DBDriver' => string (6) "MySQLi"
        'DBPrefix' => string (0) ""
        'pConnect' => boolean false
        'DBDebug' => boolean true
        'charset' => string (7) "utf8mb4"
        'DBCollat' => string (18) "utf8mb4_general_ci"
        'swapPre' => string (0) ""
        'encrypt' => boolean false
        'compress' => boolean false
        'strictOn' => boolean false
        'failover' => array (0) []
        'port' => integer 8889
        'numberNative' => boolean false
        'foundRows' => boolean false
        'dateFormat' => array (3) [
            'date' => string (5) "Y-m-d"
            'datetime' => string (11) "Y-m-d H:i:s"
            'time' => string (5) "H:i:s"
        ]

    ]
I changed "localhost" to "127.0.0.1",  just as a test and tried running the migration again, and got the same result. I checked the connection with both the CLI and a PHP script and had no issues.
I'm using MAMP as my development enviroment, and it's running PHP8.3.9 and MySQL8.0.35.
Any suggestions or pointers in the right direction would be greatly appreciated.

PHP, the Dark Horse No One Saw Coming In PHP AI Agents development

Codigniter 4.6.1 not loading config files based on environment

$
0
0
I have an environment, apart from development and production, called "sandbox", and I have created "Config/sanbox/Apx.php". Am able to access values in the "Config/Apx.php" but unable to Access values in the Config/sandbox/Apx.php, even when I set the environment to sandbox. I have also created Boot/sandbox.php. The environment loads correctly, but codeigniter does not load the sanbox configuration. Any help ? I need to have the sandbox configuration for the custom configuration.
Thanks
<?php namespace Config\sandbox;

use CodeIgniter\Config\BaseConfig;

class Apx extends BaseConfig
{
    public string $logo_url = 'img/sanbox_logo.png'
;

}

No web server configuration

$
0
0
Hello, I was wondering why there were no webserver configs,
a simple .htaccess config for apache would be really usefull.

Error in Model class "must implements abstract method idValue" after up to V 4.6.1

$
0
0
Updated the application to version 4.6.1 via composer. As a result, such an error in the classes BaseModel and Model.
Replaced the class BaseModel code from https://github.com/codeigniter4/CodeIgni...eModel.php
And now everything works.
On github in BaseModel class the method is called getIdValue, not idValue.

How to Install CodeIgniter 4 on Local Machine – Step-by-Step Guide

$
0
0
Hello everyone,
I’m new to CodeIgniter and wanted to share a simple step-by-step guide for installing CodeIgniter 4 on your local machine. It’s pretty straightforward:
  1. Download the latest CodeIgniter 4 release from the official site.
  2. Extract the files to your local web server’s root directory (like
    Code:
    htdocs
    for XAMPP).
  3. Make sure you have PHP 7.3 or higher installed.
  4. Open your terminal, navigate to the project folder, and run
    Code:
    php spark serve
    to start the built-in development server.
  5. Open your browser and go to
    Code:
    http://localhost:8080
    to see the welcome page
    If anyone encounters issues with permissions or PHP extensions, feel free to ask here!
Happy coding!

Configuring the Database Connection in CodeIgniter 4

$
0
0
Hi all,
After installing CodeIgniter 4, the next important step is setting up your database connection. Here’s how you do it:
  • Open
    Code:
    app/Config/Database.php
    file.
  • Update the
    Code:
    $default
    group settings with your database credentials (hostname, username, password, database name).
  • Make sure the database driver matches your DBMS (e.g., MySQLi for MySQL).
  • Save the file and test your connection by running a simple model query.
If you want to use environment variables for better security, CodeIgniter supports that too! Just edit the
Code:
.env
file at the root and set your DB credentials there.
Let me know if you want me to share sample code snippets or troubleshoot errors.
Cheers!

How to Integrate Bootstrap or Tailwind CSS with CodeIgniter

$
0
0
Have you ever tried integrating Bootstrap or Tailwind CSS into your CodeIgniter project? What’s the best way to include these frameworks—using a CDN or downloading and linking them locally? Also, where do you usually place your CSS files in the CodeIgniter folder structure, and how do you manage responsive layouts within your views? Share your approach or any issues you faced while working with these CSS frameworks in CodeIgniter.

login bug on a codeigniter project

$
0
0
Hello! I have a project that I installed on a hostinger host running php 8. On login screen after user and password it always returned to login screen. After some tips on internet, I change the hostinger server to php 5.6 and the project runned ok. But I´m trying to make it run on my local machine for development and have the same problem on login screen. How to fix it on IIS?

Already tried to change version of PHP on my computer without succsess! It seems to be a route problem on codeigniter

Is CodeIgniter right for me?

$
0
0
Hi there,
Greetings to all as this is my first post.
I am a complete novice at this business of frameworks.
I would like to start learning and using CodeIgniter as I have read many positive reviews about it.
Though I have developed applications using php but none have utilised the MVC principles.
I have tried to learn programming by myself using examples and snippets of codes, and always try to adhere to best practice.
I would appreciate if seasoned CI developers answer a very fundamental question for me:
The question is about re-using libraries, classes, functions, etc., in a modular framework environment.
[which I suppose could be applicable to all PHP frameworks, not necessarily to CI]
Let's say that you are developing a project that needs a good search function in it.
Now you come across an open-source application and/or you have purchased an application that has got that 'desirable' search facility built in it.
Can I re-use that in my project? 

Thank you in advance for any helpful suggestion and/or advice.

LeekCMS - A Full-featured CMS built with CodeIgniter 4

$
0
0
Hello CI4 Community,
I'd like to introduce a project I've been developing called LeekCMS. It's a fully-featured CMS built from the ground up using CodeIgniter 4, designed specifically for managing and monetizing digital content.
Quote:Goal: To create a CMS that is lightweight, fast, and ready-to-use out of the box for creators selling digital content such as videos, photo galleries, or paid memberships.

? Core Technologies:
  • Framework: CodeIgniter 4 (no 3rd-party CMS base)
  • Database: MySQL
  • Cloud Storage: Amazon S3-compatible
  • Dashboard: Built-in from scratch (no external themes/plugins)

? Key Features:
  • User management with Member Levels
  • Point-based and Subscription-based monetization
  • Full support for Video & Gallery content with Pay-per-view option
  • S3 integration with automatic thumbnail & folder scan for image galleries
  • Auto-generated Pricing & Activation Pages based on Member Levels
  • Activation Code System for points or member upgrades (independent from payment gateways)
  • Built-in Ads Module
  • Custom CSP Header Management via Admin Panel
  • Multi-language support (coming soon)
  • Admin dashboard 100% custom built with a simple, clean UI
  • Email settings, Analytics & Tracking, Site customization all within GUI

? A note from the developer:
This project is solo-developed by me, and while most of the core logic is complete, I'm currently looking for contributors or suggestions — especially help with building the multi-language module.
Many advanced features were created with end-user simplicity in mind, and I would love to bring this to a broader CI4 audience.
Quote:? The first GitHub version will be shared privately to early interested users. It will be made public 2 weeks later.
? Register your interest via Email: dev.codewithai@gmail.com

?️ Screenshots:

[Image: LeekCMS.jpg]
  • Dashboard
  • Member Levels
  • Video Management
  • Gallery Management
  • Page Builder
  • Settings (Email, Ads, Analytics, S3)

? Future Plan:
  • Open-source under MIT License (with optional paid Pro version)
  • SaaS cloud version: deploy-on-click, integrated domain + hosting (for creators to launch instantly)
  • Pro version includes direct Payment Gateway integrations (PayPal, Stripe, etc.)
  • Community Plugin System
  • Install wizard (
    Code:
    install.php
    ) for easy deployment
  • Improved Multi-language system with GUI text manager
  • Admin theming system (dark/light/custom themes)
  • Potential integration into CI4 official Showcase or community team

? Want to explore or contribute?
  • GitHub link: (Coming soon)
  • Live demo: (Coming soon )
I'm opening this topic to gather feedback, suggestions, or even contributors.
If LeekCMS is considered helpful, I'd be honored to see it listed in CI4's official showcase. ?
Thanks for reading!
Best,
Trí

PDF attachment download not working in email in IOS/MAC/APPLE

$
0
0
Hi
I am sending pdf as attachment in email, it works fine when sending "inline", but I found issue, inline pdf is not working properly in ios/mac/apple. So I tried to send force downloadable attachment, it attaches file and I am able to download file, but it doesn't show file content and shows error "Failed to load PDF document." (https://prnt.sc/x0S_mf47G4c4). File showing corrupted on  ios/mac/apple and gmail also.
I have checked the file path, it's correct and same file works fine in inline mode.
I tried the followings, but doesn't worked
PHP Code:
1. $email->attach($attachment'attachment'basename($attachment), 'application/pdf'); 
PHP Code:
2. $email->attach($attachment'attachment''filename.pdf''application/pdf'); 
PHP Code:
3. $tempPath WRITEPATH 'temp/' uniqid() . '.bin';
copy($attachment$tempPath);
$email->attach($tempPath'attachment''document.pdf''application/octet-stream'); 
I am sending dynamically created pdf, which creates on server, then I send it in email. I also tried putting the static PDF on server, that too doesn't worked.
below is my code to send email, please help to resolve this issue.
PHP Code:
function sendEmail($data = [])
{
    if ($data) {

        $email = \Config\Services::email(true);
        $email->clear(true);

        $email->setFrom($data['fromEmail'], $data['fromName']);
        $email->setTo($data['toEmail']);

        if (isset($data['ccEmail']) && !empty($data['ccEmail'])) {
            $email->setCC($data['ccEmail']);
        }

        if (isset($data['bccEmail']) && !empty($data['bccEmail'])) {
            $email->setBCC($data['bccEmail']);
        }

        $email->setSubject($data['subject']);
        $email->setMessage($data['message']);

        if (isset($data['attachments']) && count($data['attachments']) > 0) {
            foreach ($data['attachments'] as $attachment) {
                $email->attach($attachment);
            }
        }

        $res $email->send();        
        
// $error = $email->printDebugger();

        return $res;
    }


Thanks

Alternative multisite structure - problems? concerns?

$
0
0
I wanted to accomplish in CI4 what I was doing in CI3 - have a system folder that was shared by multiple sites/projects and upgrade them individually as their code became (or was confirmed as) ready for the new version.

Using this approach, when a new release of CI3 was available, I would immediately install the new framework, but this wouldn't affect any existing code. Only when I was ready, I would point a site/project to the new system code, and I could revert that immediately and fully if something failed in a major way.

I think I have this working in CI4, but I'd like to know if anyone sees problems or concerns with how I'm doing this now. Life's been too busy for me to deal with upgrading things from CI3, but I'm now at a point where I can't delay further, thus the timing of this question.

In the following, structures assume a manual installation. I don't use Composer and have no idea how this would impact Composer-installed CI4.

The differences between how I'm doing this and what the documentation suggests are file organization and using an absolute path to the system folder in Config/Paths.php

The documentation suggests the following structure for a manually-installed multi-site CI4:
Code:
foo/
    app/
    public/
    tests/
    writable/
    env
    phpunit.xml.dist
    spark
bar/
    app/
    public/
    tests/
    writable/
    env
    phpunit.xml.dist
    spark
codeigniter4/system

My approach, allowing multiple CI4 system/core versions, looks like this:
Code:
foo/
bar/
ci4_5_8/
ci4_6_0/
ci4_6_1/
(I'm actually starting at 4.6.1, so the older versions there are just for illustration.)

In Paths.php I have:
Code:
public string $systemDirectory = '/server/projects/ci4_6_1';

I think this explains enough, but let me know if you have questions about what I mean. My question is: are there any risks (especially regarding security or stability) here that I should be wary of? It seems like a straightforward variation, but dealing with framework code that I don't have time to analyze in depth makes me a little nervous about variations.
Viewing all 14343 articles
Browse latest View live


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