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

Call to a member function get() on null Error

$
0
0
Sometimes weird things happens...
I'm developing my web site locally on my PC...things run quite fine...
I have installed Codeigniter Shield ...and now I got the following error:

[Image: basecontroller_error.png]

Any help or hint to fix the issue? Thanks a lot

In my Base Controller I have the following code to have multi language functions:
Code:
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);
        // Preload any models, libraries, etc, here.
        // E.g.: $this->session = service('session');
/**
        * E.g.: $this->session = \Config\Services::session();
        * Ensure that the session is started and running
        */
        if (session_status() == PHP_SESSION_NONE) {
$this->session = Services::session();
        }
$config = new App();
        $language = \Config\Services::language();
        $locale = $this->session->get('locale') ?? $this->request->getLocale();
        $language->setLocale($locale);
       
        $this->viewData['locale'] = $locale;
        $this->viewData['supportedLocales'] = $config->supportedLocales;
    }

Auth Shield and multilanguage

$
0
0
Hello all,
I use SHIELD for authorization
My application is multilingual
The [users] table has a [multi] column
How do I set a session from the [multi] column after logging in.
I use entry in:
PHP Code:
BaseController.php
//...

public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
{
    // Do Not Edit This Line
    parent::initController($request$response$logger);

    // Add these lines
    $session = \Config\Services::session();
    $language = \Config\Services::language();
    $language->setLocale($session->lang);
}
//... 
Thank you

query builder updateBatch behavior on 4.6.x

$
0
0
I come from 4.1.9 (was stuck in PHP7.3 for a long time) and upgrade to 4.6.1 and i notice a change in updateBatch behavior :

PHP Code:
model('Foo')->builder()->updateBatch([
[
'id' => ,
'content' => 'bar',
],
[
'id' => ,
'content' => 'bim',
'plus' => 'tac',
],
],
'id') ; 

that updateBatch with array structure differences worked in 4.1.9 and does not work in 4.6.x

Is that an expected behavior or is it a bug that will be fixed ?

thanks for your attention

twig and view cell

$
0
0
Hi all,
When i try to use view cells and twig i get this error
Twig\Error\SyntaxError
The arrow function argument must be a list of variables or a single variable in "blog/index.twig" at line 15
at line
Code:
<li class="list-inline-item">Tags : {{ view_cell('App\Cells\TagsCell::getOne',['article_id' => article.id ]) }}</li>
Does someone can help ?
Thanks
Eric

These 20 Awesome API Clients Will Change How You Work with APIs

Shield problem redirecting in hosting

$
0
0
Hi , i have an application that work fine in localhost .

I upload file on hosting but when i try to login with shield it return on login page without error message , if i see log i have : 

INFO - 2025-06-13 15:53:33 --> REDIRECTED ROUTE at https://mysite.it/login

it seem that not save user session:
__ci_last_regenerate|i:1749823269;csrf_test_name|s:32:"06d7c9016ed344db8ac20881c5c05d79";_ci_previous_url|s:38:"https://mysite.it/index.php/login";

wath can i do ?

Site main page is not working

$
0
0
Good afternoon. We have a website running on Codeigniter 4. The website has been working stably for more than three years, but yesterday something happened and the main page of the website stopped working, the server issues a 500 error. However, all other pages of the site are working correctly. Part of the server log is attached.

PHP Fatal error: Uncaught ErrorException: file_get_contents(/home/c/ck42654/app/Config/Modules.php): failed to open stream: Permission denied in /home/c/ck42654/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php:172
Stack trace:
#0 [internal function]: CodeIgniter\\Debug\\Exceptions->errorHandler(2, 'file_get_conten...', '/home/c/ck42654...', 172, Array)
#1 /home/c/ck42654/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php(172): file_get_contents('/home/c/ck42654...')
#2 /home/c/ck42654/vendor/codeigniter4/framework/system/Config/Config.php(150): CodeIgniter\\Autoloader\\FileLocator->getClassname('/home/c/ck42654...')
#3 /home/c/ck42654/vendor/codeigniter4/framework/system/Config/Config.php(83): CodeIgniter\\Config\\Config::createClass('Modules')
#4 /home/c/ck42654/vendor/codeigniter4/framework/system/Common.php(126): CodeIgniter\\Config\\Config::get('Modules', true)
#5 /home/c/ck42654/vendor/codeigniter4/framework/system/Config/BaseConfig.php(85): config('Modules')
#6 /home/c/ck42654/vendor/codeigniter4/fra in /home/c/ck42654/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php on line 172

running codeigniter in a subdirectory + legacy autorouting results in 404

$
0
0
I have a codeigniter 4 app that has to live in a shared hosting enviroment and has to be in a subdirectory.
The app has been developed with legacy autorouting enabled.
The app has indexPage as index.php

All the autorouting routes end up throwing a 404 with the "index.php is not a valid controller name" statement.

1. Steps to Reproduce
2. get an apache webserver
3. set indexPage  as index.php in your app/Config/App.php
4. install codeigniter in a subdirectory:
/var/www/html/code-igniger-app
/var/www/html/other-apps-here
this way you'll access the app from http://localhost:8080/code-igniger-app/index.php
5. enable legacy autorouting and create a controller

The problem seems to be that having codeigniter 4 in a subdirectory results in the $_SERVER["SCRIPT_NAME"] variable to become: "/code-igniger-app/public/index.php".
If the SCRIPT_NAME has "/public" the parseRequestURI method from the CodeIgniter\HTTP\SiteURIFactory class on line 137 does not remove "/code-igniger-app/index.php" from the uri and it tries to use index.php as the controller name.

I have opened this issue on github: https://github.com/codeigniter4/CodeIgni...ssues/9602 but I've been told this is a misconfiguration, I tried to follow the official guide but I could not get it to work, can someone help me figure out where I've gone wrong?
Thanks

Site main page is not working

$
0
0
Good afternoon. We have a website running on Codeigniter 4. The website has been working stably for more than three years, but yesterday something happened and the main page of the website stopped working, the server issues a 500 error. However, all other pages of the site are working correctly. Part of the server log is attached.
How can I fix this error?

PHP Fatal error: Uncaught ErrorException: file_get_contents(/home/c/ck42654/app/Config/Modules.php): failed to open stream: Permission denied in /home/c/ck42654/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php:172
Stack trace:
#0 [internal function]: CodeIgniter\\Debug\\Exceptions->errorHandler(2, 'file_get_conten...', '/home/c/ck42654...', 172, Array)
#1 /home/c/ck42654/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php(172): file_get_contents('/home/c/ck42654...')
#2 /home/c/ck42654/vendor/codeigniter4/framework/system/Config/Config.php(150): CodeIgniter\\Autoloader\\FileLocator->getClassname('/home/c/ck42654...')
#3 /home/c/ck42654/vendor/codeigniter4/framework/system/Config/Config.php(83): CodeIgniter\\Config\\Config::createClass('Modules')
#4 /home/c/ck42654/vendor/codeigniter4/framework/system/Common.php(126): CodeIgniter\\Config\\Config::get('Modules', true)
#5 /home/c/ck42654/vendor/codeigniter4/framework/system/Config/BaseConfig.php(85): config('Modules')
#6 /home/c/ck42654/vendor/codeigniter4/fra in /home/c/ck42654/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php on line 172

Multi-dimensional Array in POST

$
0
0
Hi,
I make an AJAX request in POST to CI, sending some data, including some data in the format:

Code:
const args: {
"field1": {"field2":value}
};


If I print $this->request->getPost(), I display:

PHP Code:
Array(
  [field1] => Array
    (
        [field2] => value
    
)


but if I try to print $this->request->getPost(field1.field2) I always get an empty value.

Am I wrong in the declaration?

transStatus error

$
0
0
Hi
What am I doing wrong?

PHP Code:
        $edb = \Config\Database::connect();
        $res $edb->prepare(function ($edb) {
            $query "select * from test limit :limit";
            return $edb->query($query);
        });
        $edb->transStart();
        $results $res
            
->execute(['limit' => 1])
            ->getResultArray();
        $edb->transComplete(); 
Cannot access protected property CodeIgniter\Database\Postgre\Connection::$transStatus
\Database\BasePreparedQuery.php at line 141

Which team do you want to win?

$
0
0
Hello everyone!

The FIFA Club World Cup is taking place in the USA.

Which team do you want to win?

Bugs in Tutorial CI4

$
0
0
Hi CodeIgniter Team,
just started learning Codeigniter and doing step by step your Tutorial.
In:
https://codeigniter.com/user_guide/tutor...how-method
In Controller also in Method you use show instead of view and that doesn't work, it should be named to view
Should be changed in Routing "Routes.php", in Controller "News.php"
it was mixed with view and show

Website Rendering Issue

$
0
0
Anybody know about website Rendering issues? I have website showing good live but when i check my website Live Test HTML code from GSC it show many section up and down, nothing align, why this happening, any developer know why?

Bootstrap 5.3.7 Released.


Looking to get back into Codeigniter

$
0
0
Hi peeps, just wanted to say hi, because I'm so happy to rediscover CodeIgniter.

Loved CodeIgniter back in the day, although I did not do anything big or advanced with it.

CodeIgniter 4 is looking great and it's still so fast and straightforward.

Professionally (and personally) I've mostly used Joomla! and WordPress for years and years. Magento as well (up to version 2).

Other than development, I've been a ecommerce-/marketing manager for years as well.

As an old school dev, I really don't want to learn how to create Gutenberg blocks etc. I never had the time or a reason to become a javascript wiz or learn React.

Although I will probably try Vue.js with CodeIgniter for fun.

I was a big CMS and framework nerd back in the day. Had to try almost everything Smile

CMS's are great, especially for when multiple people are working on content. But for personal projects their structure can be a pain. I'm so used to fight WordPress that when using CodeIgniter I have to remind myself that it's OK to do things like I want.

Although both WordPress and Joomla! have CLI, task managers etc. Joomla! is probably my #1 (version 5 is really good and the code is modern), but the implicit demand and awareness from clients is WordPress.

As for the short term with CodeIgniter:
  • Go through a bunch of tutorials / buy books or courses (if any)
  • Create a few personal projects:
  • As mentioned above, something that uses vue.js (admin of some sort/web app)
  • API integrations
  • Probably a Programmatic SEO project of some sort (probably data presentation from some dataset / AI generation or a combination of both)
  • Simple CMS (essentially just admin for the projects, I'm not going to create a generic CMS)
  • Something else?
Anyway, just a few random thoughts I wanted to express.

Thankful for the forum and I'm hoping to participate, going forward.

After GIT Clone: Call to a member function routes() on null

$
0
0
Good morning,

I have a problem that I can neither solve nor understand:
Let me explain better:

I develop locally, I see the site with php spark serve. everything is perfect.
I do git clone on a remote machine.
I then run composer install and then composer update to install and update all the dependencies.

Of course I go to update app.baseURL with the address of the remote machine, but I get the error:

Call to a member function routes() on null

The first thing that comes to mind is the shield. So I go to check if the shield is installed correctly.

After doing this, I am completely blocked and I don't know what else to check.

CodeIgniter v4.6.1 Command Line Tool - Server Time: 2025-06-25 12:44:13 UTC+02:00

[Error]
Call to a member function routes() on null
at APPPATH/Config/Routes.php:262

Line 262:

Code:
service('auth')->routes($routes, ['except' => ['login', 'register', 'apiCitta']]);
$routes->get('login', '\App\Controllers\UserController::loginView');
$routes->post('login', '\CodeIgniter\Shield\Controllers\LoginController::loginAction');


Composer show:

Code:
bacon/bacon-qr-code                v3.0.1  BaconQrCode is a QR code generator for PHP.
codeigniter4/framework            v4.6.1  The CodeIgniter framework v4
codeigniter4/settings              v2.2.0  Settings library for CodeIgniter 4
codeigniter4/shield                v1.1.0  Authentication and Authorization for CodeIgniter 4
dasprid/enum                      1.0.6  PHP 7.1 enum implementation
endroid/qr-code                    6.0.8  Endroid QR Code
fakerphp/faker                    v1.24.1 Faker is a PHP library that generates fake data for you.
firebase/php-jwt                  v6.11.1 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
laminas/laminas-escaper            2.17.0  Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs
mikey179/vfsstream                v1.6.12 Virtual file system to mock the real file system in unit tests.
myclabs/deep-copy                  1.13.1  Create deep copies (clones) of your objects
nikic/php-parser                  v5.5.0  A PHP parser written in PHP
paragonie/constant_time_encoding  v3.0.0  Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
phar-io/manifest                  2.0.4  Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    3.2.1  Library for handling version information and constraints
phpunit/php-code-coverage          10.1.16 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          4.1.0  FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                4.0.0  Invoke callables with a timeout
phpunit/php-text-template          3.0.1  Simple template engine.
phpunit/php-timer                  6.0.0  Utility class for timing
phpunit/phpunit                    10.5.47 The PHP Unit Testing framework.
psr/clock                          1.0.0  Common interface for reading the clock.
psr/container                      2.0.2  Common Container Interface (PHP FIG PSR-11)
psr/log                            3.0.2  Common interface for logging libraries
sebastian/cli-parser              2.0.1  Library for parsing CLI options
sebastian/code-unit                2.0.0  Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup 3.0.0  Looks up which function or method a line of code belongs to
sebastian/comparator              5.0.3  Provides the functionality to compare PHP values for equality
sebastian/complexity              3.2.0  Library for calculating the complexity of PHP code units
sebastian/diff                    5.1.1  Diff implementation
sebastian/environment              6.1.0  Provides functionality to handle HHVM/PHP environments
sebastian/exporter                5.1.2  Provides the functionality to export PHP variables for visualization
sebastian/global-state            6.0.2  Snapshotting of global state
sebastian/lines-of-code            2.0.2  Library for counting the lines of code in PHP source code
sebastian/object-enumerator        5.0.0  Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector        3.0.0  Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        5.0.0  Provides functionality to recursively process PHP variables
sebastian/type                    4.0.0  Collection of value objects that represent the types of the PHP type system
sebastian/version                  4.0.1  Library that helps with managing the version number of Git-hosted PHP projects
setasign/fpdf                      1.8.6  FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
spomky-labs/otphp                  11.3.0  A PHP library for generating one time passwords according to RFC 4226 (HOTP Algorithm) and the RFC 6238 (TOTP Algorithm) and compatible with Google Authenticator
symfony/deprecation-contracts      v3.6.0  A generic function and convention to trigger deprecation notices
theseer/tokenizer                  1.2.3  A small library for converting tokenized PHP source code into XML and potentially other formats

trim(): Argument #1 ($string)

$
0
0
everytime i create a new project in CI4 4.6.1 with php 8.2.12 i often get this error, what is wrong?

this error comes out when i first run my application.


trim(): Argument #1 ($string) must be of type string, array given 
error at :  SYSTEMPATH\Filters\Filters.php at line 918

911      * @param array  $paths The except path patterns
912      */
913    private function checkPseudoRegex(string $uri, array $paths): bool
914    {
915        // treat each path as pseudo-regex
916        foreach ($paths as $path) {
917            // need to escape path separators
918            $path = str_replace('/', '\/', trim($path, '/ '));
919            // need to make pseudo wildcard real
920            $path = strtolower(str_replace('*', '.*', $path));
921
922            // Does this rule apply here?
923            if (preg_match('#\A' . $path . '\z#u', $uri, $match) === 1) {
924                return true;
925            }

log :
CRITICAL - 2025-06-17 01:45:17 --> TypeError: trim(): Argument #1 ($string) must be of type string, array given
[Method: GET, Route: /]
in SYSTEMPATH\Filters\Filters.php on line 918.
 1 SYSTEMPATH\Filters\Filters.php(918): trim([...], '/ ')
 2 SYSTEMPATH\Filters\Filters.php(881): CodeIgniter\Filters\Filters->checkPseudoRegex('', [...])
 3 SYSTEMPATH\Filters\Filters.php(791): CodeIgniter\Filters\Filters->pathApplies('', [...])
 4 SYSTEMPATH\Filters\Filters.php(474): CodeIgniter\Filters\Filters->processFilters('')
 5 SYSTEMPATH\Filters\Filters.php(218): CodeIgniter\Filters\Filters->initialize('')
 6 SYSTEMPATH\CodeIgniter.php(479): CodeIgniter\Filters\Filters->run('', 'before')
 7 SYSTEMPATH\CodeIgniter.php(354): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
 8 SYSTEMPATH\Boot.php(334): CodeIgniter\CodeIgniter->run()
 9 SYSTEMPATH\Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
10 FCPATH\index.php(59): CodeIgniter\Boot::bootWeb(Object(Config\Paths))
11 SYSTEMPATH\rewrite.php(44): require_once('C:\\xampp\\htdocs\\geminimenu\\public\\index.php')


 how can i solve this?

How to display uploaded file from writable/uploads

$
0
0
Hello,
I have a question. In CodeIgniter 4, how can I display the path of an uploaded file from the writable/uploads folder?

I upload various file types including images, documents, PDFs, and CSVs using the following code and store the file paths in the database.
Code:
$file->move(WRITEPATH . 'uploads', $fileName);


All uploaded records are listed on a page, and I need to open the uploaded CSV or Excel files in a new tab from this listing page.

However, I’m unable to retrieve the path from the writable/uploads folder to open it in a new tab.

Code:
<?=WRITEPATH.'uploads/'.$allList->documentCsv?>


When I copy the link and try to open it in a new tab, it downloads instead of displaying the file.

Could you please explain how to properly show the file path?

Bug paginate pager in model

$
0
0
Hai, i got a case, the issue is im just try to build pagination using paginate and pager in model. So i create manualy using service('pager') like the user guide, and i check this pager like $detail = $pager->getDetails(). but there is a bug in  $detail['uri']->getQuery().

My query string in browser 'limit=10&page=3&search=bar'
The pager getQuery didnt work well, the number page is not correct and sometimes the page is gone leaving the limit and search, every i reload the browser its a random.

Okay before that sorry for my bad english, and im newbie
Viewing all 14346 articles
Browse latest View live


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