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

version > 4.5.1 zip is missing files


Get controllers list

$
0
0
Hi guys!
I have a trouble to get controllers list due to class_exists not working well in my project.
In CI3, ControllersList library worked well, but after I upgrade it to CI4, that library returns NULL.
Anybody can help me?

Thank you in advancement.

CI-3 HMVC PHP Error

$
0
0
I am trying to get CI-3 to work on localhost with PHP 8.3 and I am getting an error in the MX Controller:

A PHP Error was encountered
Severity: 8192

Message: str_replace(): Passing null to parameter #1 ($search) of type array|string is deprecated

Filename: MX/Controller.php

Line Number: 45

Backtrace:

File: C:\wamp64\www\chichester-evening-as\application\third_party\MX\Controller.php
Line: 45
Function: str_replace


Line 45 is: $class = str_replace(CI::$APP->config->item('controller_suffix'), '', get_class($this));

Any ideas on a fix?

file comparisons running app and those vendor

$
0
0
My understanding when running "composer update"  from the root of my web application is that new versions of files will end up in vendor. I can read the upgrading
but I can if i so wish also run commands like :
[andrew@darkstar Config]$  sdiff  /srv/http/CI4-CMS/app/Config/Email.php          /srv/http/CI4-CMS/vendor/codeigniter4/framework/app/Config/Email.php

[Image: CI4-sdiff.png]


and compare say config files being used in my web app and also those that are updated which I understand are in  vendor/codeigniter4/framework
SO in the image above i can validate yes there were some chnage but only comments. So far so good.
So it looks like I can poke around in vendor/codeigniter4/framework,and files with same name as that in my running web app should be comparable.
Now then my actual composer.json which started  quite a while back looks like :
Code:
{
    "name": "codeigniter4/appstarter",
    "description": "CodeIgniter4 starter app",
    "license": "MIT",
    "type": "project",
    "homepage": "https://codeigniter.com",
    "support": {
        "forum": "https://forum.codeigniter.com/",
        "source": "https://github.com/codeigniter4/CodeIgniter4",
        "slack": "https://codeigniterchat.slack.com"
    },
    "require": {
        "php": "^8.1",
        "codeigniter4/framework": "4.5.5",
        "phpmailer/phpmailer": "^6.8"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9",
        "mikey179/vfsstream": "^1.6",
        "phpunit/phpunit": "^10.5.16"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Config\\": "app/Config/"
        },
        "exclude-from-classmap": [
            "**/Database/Migrations/**"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\Support\\": "tests/_support"
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "scripts": {
        "test": "phpunit"
    }
}







if i run composer for a new app stater eg
[andrew@darkstar Desktop]$ composer create-project codeigniter4/appstarter newApp
the composer.json file  looks like:

Code:
{
    "name": "codeigniter4/appstarter",
    "description": "CodeIgniter4 starter app",
    "license": "MIT",
    "type": "project",
    "homepage": "https://codeigniter.com",
    "support": {
        "forum": "https://forum.codeigniter.com/",
        "source": "https://github.com/codeigniter4/CodeIgniter4",
        "slack": "https://codeigniterchat.slack.com"
    },
    "require": {
        "php": "^8.1",
        "codeigniter4/framework": "^4.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9",
        "mikey179/vfsstream": "^1.6",
        "phpunit/phpunit": "^10.5.16"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Config\\": "app/Config/"
        },
        "exclude-from-classmap": [
            "**/Database/Migrations/**"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\Support\\": "tests/_support"
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "scripts": {
        "test": "phpunit"
    }
}

So a new CI4 installation using composer is very close if not identical to what I have but if i go to :


/srv/http/CI4-CMS/vendor/codeigniter4/framework
composer.json looks like :

Code:
{
    "name": "codeigniter4/framework",
    "description": "The CodeIgniter framework v4",
    "license": "MIT",
    "type": "project",
    "homepage": "https://codeigniter.com",
    "support": {
        "forum": "https://forum.codeigniter.com/",
        "source": "https://github.com/codeigniter4/CodeIgniter4",
        "slack": "https://codeigniterchat.slack.com"
    },
    "require": {
        "php": "^8.1",
        "ext-intl": "*",
        "ext-mbstring": "*",
        "laminas/laminas-escaper": "^2.13",
        "psr/log": "^3.0"
    },
    "require-dev": {
        "codeigniter/coding-standard": "^1.7",
        "fakerphp/faker": "^1.9",
        "friendsofphp/php-cs-fixer": "^3.47.1",
        "kint-php/kint": "^5.0.4",
        "mikey179/vfsstream": "^1.6",
        "nexusphp/cs-config": "^3.6",
        "phpunit/phpunit": "^10.5.16 || ^11.2",
        "predis/predis": "^1.1 || ^2.0"
    },
    "suggest": {
        "ext-curl": "If you use CURLRequest class",
        "ext-dom": "If you use TestResponse",
        "ext-exif": "If you run Image class tests",
        "ext-fileinfo": "Improves mime type detection for files",
        "ext-gd": "If you use Image class GDHandler",
        "ext-imagick": "If you use Image class ImageMagickHandler",
        "ext-libxml": "If you use TestResponse",
        "ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
        "ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
        "ext-mysqli": "If you use MySQL",
        "ext-oci8": "If you use Oracle Database",
        "ext-pgsql": "If you use PostgreSQL",
        "ext-readline": "Improves CLI::input() usability",
        "ext-redis": "If you use Cache class RedisHandler",
        "ext-simplexml": "If you format XML",
        "ext-sodium": "If you use Encryption SodiumHandler",
        "ext-sqlite3": "If you use SQLite3",
        "ext-sqlsrv": "If you use SQL Server",
        "ext-xdebug": "If you use CIUnitTestCase::assertHeaderEmitted()"
    },
    "autoload": {
        "psr-4": {
            "CodeIgniter\\": "system/"
        },
        "exclude-from-classmap": [
            "**/Database/Migrations/**"
        ]
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "scripts": {
        "test": "phpunit"
    }
}


doesnt look right to me, where is my slightly amended composer.json file located to look at when things change ?

env file and Settings package

$
0
0
Hello everyone, 
I have a question about the priority of configuration methods. If I use both env file and offical Settings Package, which config will be used in codeigniter library. 
For example, if I set different smtphost in env file and service('settings'), which one will be used as default value in email library?

Inexplicable CSRF Error

$
0
0
I'm pulling my hair out trying to figure out why CI is not matching my CSRF token value. What else could cause this error? (error is equal to "old"). What does that mean? I've got a hidden csrf field and value in my view's form with method="post". Why would it not match the one CI is looking for? I've a zillion pages with forms like this. All of the others work as expected. Usually when I get the "The action you requested is not allowed" error is because I forgot to add 
PHP Code:
<?= csrf_field() ?>


Code:
Session User Data
__ci_last_regenerate 1726847150
_ci_previous_url https://dev-bnc4-web7.bsg.na.baesystems.com/user/otp/146/satchwinston@yahoo.com
csrf_token_name a4cabeb296c28a07509bce759502297e
forgot_username 1
otp_errors 1
error The action you requested is not allowed.
__ci_vars
Array
(
    [error] => old

)

getting record id of upsert

$
0
0
Hello!
When doing upserts, is there a tidy way of retrieving the primary key (e.g. id) of the affected record afterwards?
I realize that logic is possible to use either a query or $db->insertID() after the fact to find the ID, but it would be nice if, for example, insertID() returned the id regardless of the action all in one line.

Thanks!

Deprecated Security Properties

$
0
0
I noticed in Security.php that several properties are deprecated. Is it still ok to use the following in .env?
Code:
security.redirect = true
security.csrfProtection = 'session'

best way to store tokens and api keys?

$
0
0
good morning,
i have a little question.
what is the best way in codeigniter 4  to keep tokens and passwords safe?
for example, in one of my portals, i use PayPal API. Currently i have a sort of config.php where inside i define a constant called: token to which i assign the value.
when i need the token, i call the constant.
the problem is that in case of direct access to the files that are on the server, anyone can see the token in clear.
the other path i had taken was to create a table and insert in MySql all the various tokens of the different services, obviously encrypted in MD5.
in this case, when i need the token, i call it directly through a query.

what do you think is the best method?
is there a safe place in codeigniter to store this type of data?

Get partial validated data

$
0
0
Hi, I have a question. How can I retrieve partially validated data from a validation process?

I would like to perform parallel processing: saving some data while displaying error messages for the parts that failed validation. 

I have the following code but didn't work, Any help would be greatly appreciated.

PHP Code:
if (!$this->validate($rules)) {
            $cleanData $this->validator->getValidated();
            dd($cleanData); // no data?
            $this->savePartial($cleanData);

            $errors $this->validator->getErrors();
            $error array_shift($errors);

            return $this->respond(['messages' => $this->alert(
                text$error,
                type'warning',
            )]);
        

database list

$
0
0
PHP Code:
        $this->load->dbutil();
        $dbs = $this->dbutil->list_databases();

        foreach ($dbs as $db)
        {
            if ($this->dbutil->database_exists($db))
            {
                   echo $db."<br>";
            }
        

I don't understand, but it list all databases that I have (all, not just which I use in my application).

How to list the databases defined in the database.php (only) ?

Thanks a lot !!

Auto routing and/or defining routes

$
0
0
Hello community
I'm struggling with routing in my new application. I'm coming from CI3 and am used the auto routing stuff. Now I learned about defining routes for the application. But I can't find the right solution that works for my purposes.
What I like to achieve is to route a handful of URIs to some specific controllers, some of them organised in a sub directory. Then I have all the other URIs which I'd like to route to a single controller to get the dynamic page content together.
Controllers' directory:
-- BaseController.php
-- Site.php
-- Login.php
-- Apps
-- -- Home.php
-- -- App1.php
-- -- App2.php
-- -- …
The Site controller should get every request from URIs not beginning with login or apps/appX. So I defined a route like this:
PHP Code:
$routes->get('/''Site::index');
$routes->get('/login''Login::index');
$routes->get('/(:segment)''Site::index');
$routes->get('/(:segment)/(:any)''Site::page'); 

What happens now is that all the dynamic URIs are routed to Site::index and Site::page. So far so good. The Login page also works fine. For the AppX controllers I wanted to use auto routing, because there are a lot of controllers inside the App sub directory. So I activated auto routing as mentioned in the user guide.
But I can't get it working. If I call /apps/app1 I get routed to Site::page. I guess the problem is that CI is working the defined routes before looking for a specific controller file for auto routing to it.
My questions:
Is it generally not possible to define routes when auto routing is enabled?
How can I achieve what I'm trying to?
Thanks for your help!

Safari Autofill and CSRF

$
0
0
Safari's autofill feature breaks CodeIgniter's CSRF protection. I get a "The action you requested is not allowed" error message when I let Safari auto fill a onetime passcode. I spent many hours screwing around trying to fix this problem. If I paste the passcode in myself it works. I have no idea how to fix it.

orderBy did not work when using chunk

$
0
0
I have a query using a model to perform chunk operations on data taken from the "konfirmasi_pembayaran" table and perform a join with the "users" table to get the "nama" column. This query also uses orderBy to sort the data by the "user_nama" column (which is an alias for users.nama), but the expected sorting doesn't work well when using the chunk method.

Any help would be greatly appreciated.

The query as follow:

PHP Code:
$order 0;

$model->select('konfirmasi_pembayaran.*, users.nama as user_nama')
    ->join('users''users.id = konfirmasi_pembayaran.user_id''left')
    ->where($where)
    ->orderBy('user_nama''asc')
    ->chunk(100, static function ($confirm) use (&$order$model) {
        $dataToUpdate = [
            'order_id' => ($order++),
        ];
        $model->update($confirm->id$dataToUpdate);
    }); 

Code:
"title": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
"type": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
"code": 500,
"message": "Unknown column 'user_nama' in 'order clause'",

without chunk the query is work fine:

PHP Code:
$dd $model->select('konfirmasi_pembayaran.*, users.nama as user_nama')
            ->join('users''users.id = konfirmasi_pembayaran.user_id''left')
            ->where($where)
            ->orderBy('user_nama''desc')
            ->findAll();

dd($dd); 

APPATH and SYSTEMPATH showing in Chrome Browser

$
0
0
HI Forum,
Since today, when I run my site in Chrome I constantly see orange boxes with APPATH and SYSTEMPATH setttings in my Chrome browser console!?
IS this a sort of debug mode in CI4 or a setting in the Chrome Developer tools?
I am spending quite some time to get rid of this view
No idea how to turn this off?
Any suggestions/help appreciated

8 must know open source repositories to build cool AI apps

Routing Not Working - Only Index Route Accessible

$
0
0
Hello everyone,

I'm facing an issue with routing in CodeIgniter 4. Only the index route is working, and none of my other controller methods are accessible via URLs.
Here’s what I’ve done so far:
app/Config/Routes.php
Code:
<?php

use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->post('/', 'Home::index');
$routes->get('getLeadsByDateRange', 'App\Controller\Home::getLeadsByDateRange');
$routes->post('/lead', 'App\Controller\LeadController::index');
$routes->get('/lead/getLeadsByDateRange', 'LeadController::getLeadsByDateRange');

.htaccess
Code:
<IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On

        # If you installed CodeIgniter in a subfolder, you will need to
        # change the following line to match the subfolder you need.
        # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
        RewriteBase /

        # Redirect Trailing Slashes...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

        # Rewrite "www.example.com -> example.com"
        RewriteCond %{HTTPS} !=on
        RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
        #RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
        RewriteRule ^(.*)$ index.php/$0 [L]


        # Checks to see if the user is attempting to access a valid file,
        # such as an image or css document, if this isn't true it sends the
        # request to the front controller, index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

        # Ensure Authorization header is passed along
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>


/app/Controller/Home.php
Code:
<?php

namespace App\Controllers;
use App\Models\LeadBackupModel;
use CodeIgniter\I18n\Time;
use CodeIgniter\Controller; // Extending the base controller

class Home extends BaseController
{
        public function __construct()
        {
                header('Access-Control-Allow-Origin: *');
                header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
                header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
                $method = $_SERVER['REQUEST_METHOD'];
                if($method == "OPTIONS") {
                    die();
                }
        }

        public function index()
        {
          return view('welcome_message');
        }

        public function getLeadsByDateRange()
        {
          return view('welcome_message');
;

                }
}


app/Config/App.php
Code:
public string $indexPage = '';

The PHP development team announces the immediate availability of PHP 8.3.12. This is

$
0
0
The PHP development team announces the immediate availability of PHP 8.3.12. This is a security release.

Screen size

$
0
0
Hello, friends!

What is your preferred screen size for programming (in inches)?

Custom filter class not found

$
0
0
I created a custom filtering class and configured information in Filters.php.
Page error: Class "APP \ Filters \ AuthCheckFilter" not found
codeigniter v4.5.5
AuthCheckFilter.php
PHP Code:
namespace App\Filters;

use 
CodeIgniter\Filters\FilterInterface;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;

class 
AuthCheckFilter implements FilterInterface
{
    public function before(RequestInterface $request$arguments null)
    {
        // Do something here
    }

    public function after(RequestInterface $requestResponseInterface $response$arguments null)
    {
        // Do something here
    }


Filters.php
PHP Code:
public array $aliases = [
'authfilters' => \APP\Filters\AuthCheckFilter::class,
...
  
];

public array $filters = [
'authfilters' => ['before' => 'admin/*'],
]; 
Error:
Class "APP\Filters\AuthCheckFilter" not found
SYSTEMPATH\Filters\Filters.php at line 197

How should I handle this issue?
Viewing all 14343 articles
Browse latest View live