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

ArgumentCountError

$
0
0
Hi, 
Trying to use CI4, set the routes (Config\Routes.php) like this:
PHP Code:
<?php

use CodeIgniter\Router\RouteCollection;

$appConfig config('app');
$localeRegex implode('|'$appConfig->supportedLocales);

// Custom placeholder
$routes->addPlaceHolder('locale'$localeRegex);

/**
 * @var RouteCollection $routes
 */
$routes->get('/''Home::index', ['as' => 'home']);

$routes->get('/login/lang/{locale}''Auth::loginLocale', ['as' => 'login_locale']);
$routes->match(['get''post'], '/login''Auth::login', ['as' => 'login']);
$routes->get('/logout''Auth::logout', ['as' => 'logout']); 
and have Auth Controller (Controllers\Auth.php):
PHP Code:
<?php

namespace App\Controllers;

use 
App\Models\UserModel;

class 
Auth extends BaseController
{

    public function loginLocale(string $locale)
    {
        $this->session->set('lang'$locale);
        return redirect()->route('login');
    }

    public function login()
    {
        // Redirect user to home page if already login
        if ($this->session->has('username')) {
            return redirect()->route('home');
        }

        $data['title'] = lang('App.welcome');

        if ($this->request->getMethod() === 'POST') {
            
            $rules 
= [
                'username' => 'required',
                'password' => 'required',
            ];

            $input $this->request->getPost(array_keys($rules));

            dd($input);
        }

        $data['page'] = view('auth/login'$data);

        return view('templates/blank'$data);
    }

    public function logout()
    {
        $this->session->destroy();

        return redirect()->route('login');
    }


when request URL to: http://10.55.6.34:8080/project/login/lang/en got this error:
Code:
ArgumentCountError

Too few arguments to function App\Controllers\Auth::loginLocale(), 0 passed in /home/username/workspaces/php/project/system/CodeIgniter.php on line 933 and exactly 1 expected

Any sugestion?

Thank you

There is nothing to update odd behaviour?

$
0
0
Hi,
Not sure this is the best place to post. I was struggling with a save() that kept returning the Codeigniter exception "There is no data to update" while I had in my controller defined a redirect back with a message using the hasChanged() on my entity.
I could not figure out why I was not getting my own message until I stumbled on this post: https://swww.com.pl/main/index/there-is-...eigniter-4 
Rechecking my model, I found I was exactly in that situation: I had added a column in my database but forgot to add it to the allowedFields in my model. And in my admin, if I'd submit an edit form without changes, I'd see the exception rather than my custom message.
While I find error messages usually very helpful to understand what is happening, there is no way I would have found what was happening without that post, because in this case, the problem was an unknown field in the model.
Is there a way to make the message for this case more explicit?
Thanks for your help

The header name is not valid as per RFC 7230

$
0
0
Hi

I upgraded my codeIgniter appStarter from 4.5.4 to 4.6.3 and now I'm getting a strange error
I have a Requests Library which uses:
PHP Code:
$this->client = \Config\Services::curlrequest(); 

In the same Requests class I have the following post function

PHP Code:
function post($url$datos$header false$userPwd false)
{
    
$this->client = \Config\Services::curlrequest();
    if (!
$header) {
        
$header = [
            
'Content-Type' => 'application/json',
            
'Accept' => 'application/json',
            
'Cache-Control' => 'no-cache',
        ];
    }
    
// Debugging headers
    
log_message('debug''Headers: ' print_r($headertrue));
    
$respuesta = new \stdClass();
    
$respuesta->code 200;
    
$respuesta->error '';
    try {
        
$options = [
            
'allow_redirects' => true,
            
'timeout' => 40,
            
'debug' => true,
            
'headers' => $header,
            
'body' => $datos,
        ];
        
// Add basic auth if provided
        
if ($userPwd) {
            
$options['auth'] = $userPwd;
        }
        
$response $this->client->request('POST'$url$options);
        
$respuesta->code $response->getStatusCode();
        
$respuesta->data json_decode($response->getBody());
    } catch (\
Exception $e) {
        
$respuesta->code 400;
        
$respuesta->error $e->getMessage();
        
log_message('error''Error in POST request: ' $e->getMessage());
    }
    return 
$respuesta;


When checking out logs, I see the following:

Code:
DEBUG - 2025-08-27 14:30:31 --> Headers: Array
(
    [Content-Type] => application/json
    [Accept] => application/json
    [Authorization:Basic] => MjYyODgwMzcuRE5JLk0ud32MUU1OTVEMzZENTY0NzU3
)
ERROR - 2025-08-27 14:30:31 --> Error in POST request: The header name is not valid as per RFC 7230.

When searching about this RFC message, I see it is available in the following file:

Code:
vendor/codeigniter4/framework/system/HTTP/Header.php

I see the code throwing that is

Code:
private function validateName(string $name): void
    {
        if (preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $name) !== 1) {
            throw new InvalidArgumentException('The header name is not valid as per RFC 7230.');
        }
    }

Is there anything wrong in my headers that is making validateName to throw this exception?
I'm not sure if this file was modified when I upgraded from 4.5.4 to 4.6.3 but in 4.5.4 all was working

Thanks a lot in advance for any help you can give me


Self response/solution

I was sending the authorization header as this

Code:
'Authorization:Basic' => $credentials,

Changed to

Code:
'Authorization' => 'Basic '.$credentials,

And worked. The : symbol (among others) now is not accepted in the header name

how to view a single blog details

$
0
0
public function blogview($slug = null)
    {
        $post = new PostsModel();
        //    $post = new FunctionModel();
        $post = $post->getPosts($slug);
        $data=[
            $post,
            ];
            echo print_r($post);              
    //  return view('frontend/blogview', $data);
    }

please when i process this it returns all records in the table codeigniter 4.6.3 i need help

Shield – $validFields item

$
0
0
Dear,

Can you please tell me what the $validFields variable in the Auth.php file is for?

I wanted to log in using "username" and "password", so I was happy when I found this item. So I set it in the Auth.php file:
Code:
public array $validFields = [
'username',
];

And I expected that instead of entering an email, the login window would display a request to enter a "username". But that didn't happen. So I looked for where the error was and found that the "login.php" view was missing an "if" and the code for entering a "username". So I had to edit the view.

Since the user has to edit the view, I think this item $validFields is useless, because if I have to edit the view, I might as well edit the Validation.php file, where I enter the relevant rules

Petr

Shield - Information about the logged in user

$
0
0
I need to display basic information about the logged in user, such as "username", "email", etc., but I haven't found any function that would return this information. Or at least if there was a function that would return the "id" of the logged in user.

If such a function exists, can you please tell me its name? And if it doesn't exist, can you advise me how to easily get this data?

Thank you

Petr

8 AI Productivity Tools You Should Be Exploring Right Now

[Tutorial] Sessions Files CodeIgniter 4

$
0
0
Hello community, 
After more than 4 years developing with CodeIgniter 4 and having some sites reaching over 2M unique users in 8 months,
I’d like to share my tip for letting CodeIgniter 4’s session files auto-clean in a simple French tutorial.
In this tutorial, I explain how to remove inactive sessions using PHP’s garbage collector combined with CodeIgniter 4’s session configuration.
My challenge was dealing with over 900,000 files for a high-traffic site like mine, so this tip worked and significantly lightened my servers.

GreenHoster tutorial Sessions Files

Thanks for reading,
Best regards,
Florian — a big CodeIgniter 4 fan

Why Dynamic pages links not working on Github Pipeline

$
0
0
On Github pipeline, I have the DockerBuild 100% completed successful. And on the server, the website is displaying the index/main page. On this page the static links work.  The dynamic links would all return a “Not Found. The requested URL was not found on this server.” message. 
All the dynamic links work perfectly on my local host, and are routed to the correct controllers and views. I'm using Codeigniter4.
The baseURL works. I have made updates in files like Config/App.php, Config/Autoload.php, and .env. Added .htaccess to root folder. Still on the server website, I can only open the index page, but not the other dynamic links.
 
 
.env: added app.baseURL, app_baseULR, and site_url equl.  Not working.
App/Config/App.php: Added string public string $baseURL = 'mywebsite'; Not working.
Config/Autoload.php:  Added public $helpers = ['url'];  Not working.
Experimented with Controller main.php.  Added /public after site_url.  It didn’t work.
Added .htaccess to root directory. Not working.
 
I searched online. Documents indicated that Github only works with static page. In order for dynamic routing to work, dockerization was one way to let Github handle dynamic pages. We do have a Dockerfile. Does this file need any special set up to allow dynamic links/pages work on the server?
Thanks!

r/codeigniter - coudn't post topic or post in that reddit ?

$
0
0
I don't know why this `r/codeigniter` is restricted to other than admin. If someone managing this reddit is present here can you allow anyone can post message ?
Thank you

Indo-Sakura Software Japan Co., Ltd. is Hiring!

$
0
0
Position: Full-Stack Web Developer (React.js / Node.js / AI Integration)
Location: Tokyo (On-site/Hybrid) or Remote (India & Global)
Indo-Sakura Software Japan Co., Ltd. is a CMMI Level-3 and ISO 27001 certified global technology company with headquarters in Tokyo, Japan, and development presence in India. We specialize in custom software development, mobile & web app engineering, and AI-driven digital transformation. We are looking to expand our team with a talented Full-Stack Developer to help us build world-class digital products for clients across finance, healthcare, e-commerce, and logistics.
Brief overview of some functions you will perform:
  • Collaborate with project managers and senior engineers to develop and maintain enterprise-grade applications.
  • Build clean, scalable, and maintainable code using React.js, Node.js, Express/NestJS, and PostgreSQL/MySQL.
  • Integrate Generative AI and Agentic AI modules into web and mobile solutions.
  • Suggest improvements to existing architecture, ensuring best practices and long-term scalability.
  • Implement new features, optimize existing systems, and deliver bug fixes with high reliability.
  • Work on cross-border projects bridging Japan and India, ensuring cultural and technical adaptability.
Some of the skills we are looking for:
  • Strong knowledge of JavaScript/TypeScript, React.js, and Node.js.
  • Experience with REST APIs, GraphQL, and third-party integrations.
  • Good understanding of relational databases (PostgreSQL, MySQL) and NoSQL (MongoDB, Redis).
  • Familiarity with cloud platforms (AWS, GCP, Azure) and CI/CD pipelines.
  • Exposure to AI frameworks and API integrations (preferred).
  • Proficiency with Git and collaborative workflows.
  • Strong analytical, problem-solving, and communication skills.
  • Ability to work independently and in cross-functional teams across time zones.
How to Apply:
Send your resume, portfolio, salary expectations, and a short cover letter to careers@Indosakura.com. Please include links or references to past projects, especially in React, Node.js, or AI integrations.
About Indo-Sakura:
Indo-Sakura Software Japan Co., Ltd. is a global software and IT consulting company bridging Japanese precision with Indian innovation. With a strong focus on software engineering, mobile app development, and AI-driven solutions, we serve clients across industries such as finance, logistics, healthcare, and education. Our team works across Tokyo and India, delivering high-quality, secure, and scalable digital solutions that empower businesses to innovate and grow.

Asking for it?! Node,Express vs CodeIgniter

$
0
0
How does the RESTful module work? Any expertise in using it for a web application.
The app is a dashboard that consumes Generative AI services like ChatGPT and Synethesia to build out various for of content for Blogs and Podcasts. Eventually I would like to have it trained on provided datasets with a vector DB. 
I might build an MCP server to give CodeIgniter a trial run.

Supptr

$
0
0
I'd like to share with you a project I've developed over many years as a side project: Supptr  

I created it to be a business hub. While it's primarily a directory of both local and international businesses, you can also add your products and services. If you have a startup project, you can list it. In short, it's a platform that can help you develop your business network, and best of all, it was built with CodeIgniter 4. Proudly.

Supptr.com

P.S. If you have a company you'd like to add, I'd be delighted if you'd support it with a membership. It's free.

What is a UML diagram? Types, examples & how to create one

Please help me, Codeigniter 4 project without the ability to set the document root.

$
0
0
This is my base URL on Config/App: https://pantradeglobal.com/raymond_new_p...bal/public

This is my htaccess on root folder:
============================
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ raymond_new_pantradeglobal/public/$1 [L]
</IfModule>
<FilesMatch "^\.">
    Require all denied
    Satisfy All
</FilesMatch>


=======================
This is my htaccess on the public folder: 
=======================

Code:
# Disable directory browsing
Options -Indexes
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    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>
<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end

=======================

It works, but my URL becomes very ugly like : https://pantradeglobal.com/raymond_new_p...c/register or https://pantradeglobal.com/raymond_new_p...blic/login 

I set it up like this because i use a web hosting that can't set the document root for the main domain (it can only set document root for the subdomain using their HTML interface), is there a way so i can make the base URL in Config/App as https://pantradeglobal.com so the URL becomes https://pantradeglobal.com/web/register instead of https://pantradeglobal.com/raymond_new_p...b/register?

Documentation on the Codeigniter manual: https://codeigniter.com/user_guide/insta...g-services
The server use LiteSpeed, not Apache.

This is my project structure:
/public_html/.htaccess (the root htaccess)
/public_html/raymond_new_pantradeglobal (the codeigniter project files and public folder)
/public_html/raymond_new_pantradeglobal/public (the public folder with the second .htaccess)

Is learning PHP still worth it in 2025?

$
0
0
Hello,
I just finished a course in HTML, CSS, JavaScript focusing on Frontend, but then I was a bit stuck on which language to continue with. After researching many options, I quite like PHP, even though I see people often criticize it and the job market doesn't seem as "hot" as before.

In 2025, is learning PHP still a good direction for beginners?

Does PHP currently have enough potential to do quality personal projects?

I hope to receive sharing from those who are working in PHP or have followed this direction so that I can have a clearer direction.
Thank you so much

moving from myth-auth to Shield

$
0
0
Hi,
My current project uses myth-auth to login/manage users and I would like to move to Shield.
I currently have over 500 users which I need to migrate,  however, I'm concered about passwords. 
Does Shield use the same password hashing standard as myth-auth,  meaning I can programatically move my users (with myth-auth password hash) to the Shield, or will I need each user to recreate their password once Shield is implemented?
Many thanks.

Shield Email and Identities

$
0
0
Hi,
I have recent installed Shield to my project, but am a little confused. 
I understand Shield allows flexibility to use a number of authentication methods including email/password. However, at users and auth_identities tables, I do not see an email column. 
users table contains 
  • username column (varchar 30)
auth_identities table contains
  • name column (varchar 255)
Therefore, I do not see how creating a user from the documented example would work ?
Code:
$user = new User([
    'username' => 'foo-bar',
    'email'    => '[email protected]',
    'password' => 'secret plain text password',
]);
$users->save($user);

Also, it is my interpretation of the documentation, should bespoke data be required, this should be done by extending auth_identities table. 
By adding an email column to  auth_identities table I still cannot see the create user example working.
Any advice would be welcome.

Trying to use helper within custom library

$
0
0
Hi- 
I'm having trouble using the text helper in a custom library.  When I use:
Code:
helper('text');
inside my library, I get the error:  Class "App\Libraries\DateTime" not found
I would like to use the function random_string in my library but I can't figure out how to point correctly to the helper? 

Thanks!

You can open a startup in open-source and quit your daily job

Viewing all 14348 articles
Browse latest View live


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