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

Practices for Building Healthcare Software with CodeIgniter

$
0
0
Hi everyone,
I’ve been using CodeIgniter for a few web development projects, and I’m now considering it for a healthcare software application. As I dive deeper into the project, I’m looking for best practices, tips, or resources on using CodeIgniter to build secure, scalable healthcare applications.
One of the challenges I’m facing is ensuring HIPAA compliance while maintaining a seamless user experience. I came across a company that specializes in healthcare software development services and they mentioned using CodeIgniter for similar projects. They highlighted some specific strategies for managing sensitive patient data securely within web applications, which I thought could be really helpful.
Has anyone here worked on healthcare-related applications using CodeIgniter? I’d love to hear about your experiences, challenges, and any advice you might have!
Thanks in advance!

Basic question about constants

$
0
0
Hi.

I want to define some values as a constant.

Normlay it should done in the config>constants.php

In my case i want to create the constant a bit later in a library.

In the library i do it in this way "define('mynewconstant', $myarray);"

So in CI4 i can access all constants from the config file by the name of them without anything else.

in Config file is "define('thiscontant', array();" i can access with "print_r(thiscontant)";

The same way doesnt work with my defined constant from the library why it is so?

Upgrading Project Space

$
0
0
Hi,
I am new at this and trying to upgraded 4.5.7 to 4.5.8 .
The below statement is in the update instructions.
I must have selective eyesight to brain connection and have read this in the past, but ignored it.
------------------------
Some files in the project space (root, app, public, writable) received updates. 
Due to these files being outside of the system scope they will not be changed without your intervention.
-----------------
What does "your intervention "mean?
Does it mean I copy specific file from vendor/codeigniter4/framework into the project space 
and then add my changes if any to the copied file?

If that is the answer and I had not done this for all the previous updates I had done in the past.
What would be the correct way to fix my lack to doing updates correctly?
Maybe, create a new appstarter app and then compare file contents to more the appstarter to my correct application files 
Then copy the changed files and then add my application changes to the copied files?
Thank you for your assitance.
Larry

Problems using Autoroute (Legacy) with HMVC structure

$
0
0
Hello,
I have a code developed in Codeigniter 4.5.0 with the HMVC pattern. Inside the ‘app’ folder, I have created the subfolder ‘Modules’ in which I have only one module created (‘Slink’) with the folders Config, Controllers, Models and Views.
The problem arises when I activate autoroute and I want to access any of the routes not declared in the app/Modules/Slink/Config/Routes.php file, and I get a 404 error. The most curious thing is that when I apply the php spark routes command, the routes do appear:
PHP Code:
+--------+-----------------------------+------+-------------------------------------------------------+----------------+---------------+
Method Route                      Name Handler                                              Before Filters After Filters |
+--------+-----------------------------+------+-------------------------------------------------------+----------------+---------------+
GET    | /                          »    | \App\Modules\Slink\Controllers\Home::welcome          |                |              |
GET    | ([a-zA-Z0-9]+)              »    | \App\Modules\Slink\Controllers\Shortener::direct/$1  |                |              |
auto  | /                          |      | \App\Modules\Slink\Controllers\Home::welcome          | <unknown>      | <unknown>    |
auto  home                        |      | \App\Modules\Slink\Controllers\Home::welcome          | <unknown>      | <unknown>    |
auto  home/welcome[/...]          |      | \App\Modules\Slink\Controllers\Home::welcome          | <unknown>      | <unknown>    |
auto  shortener/prueba[/...]      |      | \App\Modules\Slink\Controllers\Shortener::prueba      | <unknown>      | <unknown>    |
auto  shortener/short[/...]      |      | \App\Modules\Slink\Controllers\Shortener::short      | <unknown>      | <unknown>    |
auto  shortener/_do_shorten[/...] |      | \App\Modules\Slink\Controllers\Shortener::_do_shorten | <unknown>      | <unknown>    |
auto  shortener/direct[/...]      |      | \App\Modules\Slink\Controllers\Shortener::direct      | <unknown>      | <unknown>    |
+--------+-----------------------------+------+-------------------------------------------------------+----------------+---------------+ 
My code in app/Config/Routes.php is:
PHP Code:
<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

 
$modules_path APPPATH 'Modules/';
 
$modules scandir($modules_path);
 
 foreach (
$modules as $module) {
    if ($module === '.' || $module === '..') {
        continue;
    }
 
    if (is_dir($modules_path) . '/' $module) {
        $routes_path $modules_path $module '/Config/Routes.php';
        if (file_exists($routes_path)) {
            require $routes_path;
        } else {
            continue;
        }
    }
 } 

The code in app/Modules/Slink/Config/Routes.php is:
PHP Code:
<?php

namespace App\Modules\slink\Config;

use 
CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

 
$routes->group(
    '', ['namespace' => '\App\Modules\Slink\Controllers'], function ($routes) {
        
        $routes
->get('/''Home::welcome');

        $routes->get('(:alphanum)''Shortener::direct/$1');

        // $routes->get('shortener/prueba', 'Shortener::prueba');

    }
); 

I attach also, in case it helps, the following codes. Thank you very much in advance.

Code in app/Config/Autoload.php:
PHP Code:
*
    * @var array<string, list<string>|string>
    */
    public $psr4 = [
        APP_NAMESPACE  => APPPATH,
        'Modules'      => APPPATH 'Modules',
 
'Modules\Slink' => APPPATH 'Modules\Slink',
    ]; 
Code in app/Config/Autoload.php:
PHP Code:
namespace Config;
use 
CodeIgniter\Config\Routing as BaseRouting;
/**
 * Routing configuration
 */
class Routing extends BaseRouting
{
    /**
    * For Defined Routes.
    * An array of files that contain route definitions.
    * Route files are read in order, with the first match
    * found taking precedence.
    *
    * Default: APPPATH . 'Config/Routes.php'
    *
    * @var list<string>
    */
    public array $routeFiles = [
        APPPATH 'Config/Routes.php',
        // APPPATH . 'Modules/slink/Config/Routes.php'
    ];
    /**
    * For Defined Routes and Auto Routing.
    * The default namespace to use for Controllers when no other
    * namespace has been specified.
    *
    * Default: 'App\Controllers'
    */
    public string $defaultNamespace 'App\Modules\Slink\Controllers';
    /**
    * For Auto Routing.
    * The default controller to use when no other controller has been
    * specified.
    *
    * Default: 'Home'
    */
    public string $defaultController 'Home';
    /**
    * For Defined Routes and Auto Routing.
    * The default method to call on the controller when no other
    * method has been set in the route.
    *
    * Default: 'index'
    */
    public string $defaultMethod 'welcome';
    /**
    * For Auto Routing.
    * Whether to translate dashes in URIs for controller/method to underscores.
    * Primarily useful when using the auto-routing.
    *
    * Default: false
    */
    public bool $translateURIDashes false;
    /**
    * Sets the class/method that should be called if routing doesn't
    * find a match. It can be the controller/method name like: Users::index
    *
    * This setting is passed to the Router class and handled there.
    *
    * If you want to use a closure, you will have to set it in the
    * routes file by calling:
    *
    * $routes->set404Override(function() {
    *    // Do something here
    * });
    *
    * Example:
    *  public $override404 = 'App\Errors::show404';
    */
    public ?string $override404 null;
    /**
    * If TRUE, the system will attempt to match the URI against
    * Controllers by matching each segment against folders/files
    * in APPPATH/Controllers, when a match wasn't found against
    * defined routes.
    *
    * If FALSE, will stop searching and do NO automatic routing.
    */
    public bool $autoRoute true;
    /**
    * For Defined Routes.
    * If TRUE, will enable the use of the 'prioritize' option
    * when defining routes.
    *
    * Default: false
    */
    public bool $prioritize false;
    /**
    * For Defined Routes.
    * If TRUE, matched multiple URI segments will be passed as one parameter.
    *
    * Default: false
    */
    public bool $multipleSegmentsOneParam false;
    /**
    * For Auto Routing (Improved).
    * Map of URI segments and namespaces.
    *
    * The key is the first URI segment. The value is the controller namespace.
    * E.g.,
    *  [
    *      'blog' => 'Acme\Blog\Controllers',
    *  ]
    *
    * @var array<string, string>
    */
    public array $moduleRoutes = [];
    /**
    * For Auto Routing (Improved).
    * Whether to translate dashes in URIs for controller/method to CamelCase.
    * E.g., blog-controller -> BlogController
    *
    * If you enable this, $translateURIDashes is ignored.
    *
    * Default: false
    */
    public bool $translateUriToCamelCase false;

retrive form data in controller method in codeigniter 4 and routs requirements

$
0
0
Hi everyone;
i have a form submission in my view page as follow:

PHP Code:
  <form class="propertyForm" method="POST" action="<?= url_to('props.estimate.price'); ?>">

        <label for="roomCount" style="display: block; margin: 5px 0;">Room Count:</label>
        <input type="number" name="roomCount" id="roomCount" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="size" style="display: block; margin: 5px 0;">Size (sq ft):</label>
        <input type="number" name="size" id="size" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="floor" style="display: block; margin: 5px 0;">Floor:</label>
        <input type="number" name="floor" id="floor" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="districtClass" style="display: block; margin: 5px 0;">District Class:</label>
        <input type="text" name="districtClass" id="districtClass" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <label for="buildingAge" style="display: block; margin: 5px 0;">Building Age Category:</label>
        <input type="number" name="buildingAge" id="buildingAge" required style="width: 100%; padding: 10px; margin-bottom: 5px;">

        <input type="submit" value="Calculate" style="width: 100%; padding: 10px;">
    </form


and here is my controller method:

PHP Code:
    public function estimatePropPrice() {
        // Log all POST data
        $postData $this->request->getPost();
        log_message('info''Received POST data: ' print_r($postDatatrue));
    
        
// Get values from input
        $roomCount $this->request->getPost('roomCount');
        $size $this->request->getPost('size');
        $floor $this->request->getPost('floor');
        $districtClass $this->request->getPost('districtClass');
        $buildingAge $this->request->getPost('buildingAge');
    
        
// Create a new point from the input data
        $testPoint = [
            'RoomCount' => $roomCount// Changed to match the database column name
            'Size' => $size,
            'Floor' => $floor,
            'District_Class' => $districtClass,
            'BuildingAge' => $buildingAge// Changed to match the database column name
        ];
..... 


but in controller i cant get the posted data;
while i add the requirements as follow to routs:

 
PHP Code:
  $routes->get('prop-estimate''Properties\PropertiesController::estimatePropPrice',['as'=>'estimate.prop.price']);
    $routes->post('estimatePropPrice''Properties\PropertiesController::estimatePropPric',['as'=>'props.estimate.price']); 

but i think i miss something;
(i use local host and zampp)
can anyone help to disolve?
thanks in advance.

Thanks to the CodeIgniter 4 Team

$
0
0
Dear CodeIgniter Team,
I wanted to take a moment to thank you once again for the many patches and improvements you’ve made to this wonderful PHP framework, which I’ve been using for over two years now.
My CMS has been growing steadily, and I’m proud to say it’s currently powering 12 French businesses.

The recent PHP 8.4.3 + CI 4.6.0 update has given a fantastic boost to my projects.
Thank you so much for this amazing work. I only wish I were more proficient with GitHub so I could contribute in a more meaningful way. 

One small request:
Do you plan to support AVIF image format uploads in the future? It’s becoming increasingly popular in the market.

Once again, I’d like to volunteer to redesign the CodeIgniter 4 homepage with a fresh and modern look to revitalize the framework’s image. I’d be happy to do it for free. Here’s Behance Portfolio

Best regards,
Florian

Heart

Where is the right place and way

$
0
0
Hi,

i want to include a kind of library to check login informations, to handle some basic functions etc. So in the library i need db-support too.

This library should be avivable on all pages and automatically also in models.

As a library i need to add this code in every file where i want to use it (i think)
"use App\Libraries\MyLib;"
and
create a new instance by
"$mylib = new MyLib();"


But i want to have access to the library without adding some code in every file.


If i create it as a "helper", i need to add a new db-connection in every function, that i dont wont too.


It should be a central place. It should be the best place for perfomance (so i dont wont to create x-instances etc.)


So is it possible as a library, or is a "service" or "helper" the better/right way to do it?

Initialization problem with Kint-php

$
0
0
Hi. I just upgraded my Codeigniter 4 using composer (as I always do) from version 4.5.7 to 4.6.0 and I get the following error when I try to run my application:
Undefined constant Kint\Renderer\AbstractRenderer::SORT_FULL

This has never happened to me before.
The file and line referenced is APPPATH/Config/Kint.php at line 44.
Any light anyone can shed on this?
Thanks in advance

CI 4.3.2 Routing issue

$
0
0
Hi all,
I couldn't find anything that looked like my problem in the forum so here goes.
My machine died and I had to recreate a LAMP stack on a newly installed Debian 12 OS.
All my projects work well except those using CI 4: every single one fails with routing issues. SO I tried to test with the default 4.3.2 download.
I added a controller (Test.php) for testing purposes. See below.
The CI setup:
Code:
<?php
namespace Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Session\Handlers\FileHandler;

class App extends BaseConfig
{
    /**
    * --------------------------------------------------------------------------
    * Base Site URL
    * --------------------------------------------------------------------------
    */
//  public string $baseURL = 'http://localhost:8080/';
    public string $baseURL = 'http://ci4-test.local/';

    /**
    * Allowed Hostnames in the Site URL other than the hostname in the baseURL.
    * If you want to accept multiple Hostnames, set this.
    */
    public array $allowedHostnames = [];

    /**
    * --------------------------------------------------------------------------
    * Index File
    * --------------------------------------------------------------------------
    */
//  public string $indexPage = 'index.php';
    public string $indexPage = '';

Everything below this is unchanged

Code:
<?php
namespace Config;
$routes = Services::routes();
/*
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
/*
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/
$routes->get('test', 'Test::index');
$routes->get('/', 'Home::index');

Everything below this is unchanged

Code:
<?php

namespace App\Controllers;

class Test extends BaseController
{
    public function index()
    {
        echo "Hello world";
    }
}

Now for the problem.
This used to work in localhost:
Code:
http://ci4-test.local/        (welcome page as expected)
http://ci4-test.local/test    (web page displaying 'Hello world')
Now I get this:
Code:
http://ci4-test.local/        (welcome page as expected)
http://ci4-test.local/test    (404)
Basically all routes pointing to controllers/methods/params result in an error 404. The only route that works is the '/' pointing to the default controller.
Since this is a brand new OS install, and a brand new LAMP stack install I am guessing the problem lies with an Apache 2 or a PHP config issue. That's been 3 days I'm racking my brains over this and can't find any lead anywhere as to what could be missing or superfluous.
Any help greatly appreciated.
Thanks all.

Codeigniter 4.6.0 Kint error

$
0
0
Upgrading from version 4.5.8 to 4.6.0, on startup I got the error "Undefined constant Kint\Renderer\AbstractRenderer::SORT_FULL". Digging a little on the code, that instruction did exists on 4.5.8 but it was removed on 4.6.0, however the upgrade keeps the instruction in place and that results in a error.
My workaround: I commented out that instruction on app\Config\Kint.php and apparently everything works (so far), but I'm not really sure that'll come back and bite me in the long run. ¿Any thoughts about this?

Possible to load files into lib and change class-object with a kind of group?

$
0
0
Hi,
i think about two thinks i want to do.
First i want to include files in my libaray -class defination with the functions of the class, thats so as not to lose track of many functions.

Also, i want to know if it is possible to change the way to access the functions from the lib in a kind ob sub-access/direction.

What i mean. The function "my_classfunction" of the lib "mylib" i normaly use by "$this->mylib->my_classfunction()"

Now i think again to make it more clear, to make groups of functions and access them by a kind of groupname for example "function funcA is in group testA, funB is in group testB"
and use it in a kind like "$this->mylib->testA->funcA()" - is something like this possible, and if, how?

Thanks a lot.

Lots of projects with CI4.6.0

$
0
0
Hello, after working with WP and Symfony for 15 years, since the beginning of January 2024, I have been working full-time with CodeIgniter on my projects, so I would like to share some of my professional achievements for France.
I wanted to thank CODEIGNITER 4.6 for this remarkable work, looking forward to a 2025 full of coding and passion <3

Loading languagefile for each controller

$
0
0
Hi,

normaly, so i know and understand it, CI has all translations in a single languagefile for each language or you have multiple files, but all files will load together.

I have a lot of translations and most of them are not necessary to load and hold.

I want to create a global file with global translations this is for general use and additional for each controller a own file. Now i want, that only this two files should load and hold and not all.

Is it possible or may there is a better idear to handle large translation-files?

Best Practices for Using CodeIgniter APIs in Mobile App Development

$
0
0
Hi everyone,
I’m working on a mobile app that connects to a backend built with CodeIgniter 4. The app needs to perform tasks such as user authentication, data retrieval, and real-time updates by interacting with RESTful APIs created in CodeIgniter.
Here’s a simplified example of how I’ve set up a RESTful API in CodeIgniter:
php
CopyEdit
Code:
namespace App\Controllers; 
use CodeIgniter\RESTful\ResourceController; 
class ApiController extends ResourceController 

    protected $modelName = 'App\Models\ItemModel'; 
    protected $format    = 'json'; 
    public function index() 
    { 
        $data = $this->model->findAll(); 
        return $this->respond($data); 
    } 
    public function create() 
    { 
        $input = $this->request->getJSON(); 
        $this->model->insert($input); 
        return $this->respondCreated(['status' => 'success', 'message' => 'Item created']); 
    } 
On the mobile app side, I’m using Axios to consume these APIs:
javascript
CopyEdit
Code:
import axios from 'axios'; 
const fetchData = async () => { 
  try { 
    const response = await axios.get('https://example.com/api'); 
    console.log(response.data); 
  } catch (error) { 
    console.error('Error fetching data:', error); 
  } 
}; 
fetchData(); 
While the setup is functional, I’m facing a few challenges:
  1. Authentication: Implementing secure API access with JWT or OAuth2.
  2. Performance: Optimizing API response time for large datasets.
  3. Real-time updates: Synchronizing data between the app and the backend effectively.
I recently came across mobile app development company that specialize in integrating CodeIgniter backends with mobile apps, but I’d like to hear from the community:
  • How do you securely implement user authentication in a CodeIgniter API?
  • What are your go-to techniques for optimizing API performance?
  • Are there any best practices for handling real-time updates in a mobile app with a CodeIgniter backend?
Looking forward to your suggestions and insights! Thanks in advance.

CodeIgniter 4 - How to autoload Database library?

$
0
0
Hello,
Please help me what should I write (and in which file) to automatically load the database library. Now I try to do it like this and it works:
Thank you!

Controllers/Test.php

PHP Code:
<?php

namespace App\Controllers;

class 
Test extends BaseController
{
    public function index(): string
    
{
        $db = \Config\Database::connect();

        $query $db->query('SELECT name FROM users');
        $data['results'] = $query->getResult();

        $data['title'] = 'Title';
        $data['description'] = 'Description';
        
        
return view('test'$data);
    }


Problem with Route

$
0
0
I'm playing around with CI 4.6, a small CRUD/Ajax app and Shield. Everything works great, but my route for the delete process is not working.  “Failed to load resource: the server responded with a status of 404 (Not Found)” in Chrome Console.

I am at a loss, maybe someone can help me.


My Function in JQuery:

Code:
    $(document).on('click', '.delete', function () {
        if (confirm('Are you sure you want to delete this product?')) {
         
         
            let id = $(this).data('id');
            $.post(`/product/delete/${id}`, {_method: 'DELETE'}, function () {
                fetchProducts();
            });
           
        }
    });

My Routes:

Code:
<?php

use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->get('/', 'Home::index');
$routes->get('/about', 'About:index');

service('auth')->routes($routes);

//service('auth')->routes($routes, ['except' => ['login']]);

$routes->group('product', ['filter' => 'session'], function ($routes) {
    $routes->get('/', 'Product::product'); // This serves the main Product page
    $routes->get('fetchAll', 'Product::fetchAll'); // Fetch all products via AJAX
    $routes->post('create', 'Product::create'); // Create a new product
    $routes->post('update/(:num)', 'Product::update/$1'); // Update a product
    $routes->post('delete/(:num)', 'Product::delete/$1'); // Delete a product
});

Any help would be appreciated.

Cheers, Thomas

Problem with like function in query

$
0
0
hi frends
I created a table for categories with these specifications:
'id'=>[
                'type'=>'INT',
                'unsigned'=>true,
                'auto_increment'=>true,
            ],
            'parent'=>[
                'type'=>'INT',
                'unsigned'=>true,
            ],
            'title'=>[
                'type'=>'VARCHAR',
                'constraint'=>'255',
            ],
            'technical'=>[
                'type'=>'TEXT',
                'null'=>true,
            ],
            'memo'=>[
                'type'=>'TEXT',
                'null'=>true,
            ],
            'status'=>[
                'type'=>'INT',
                'default'=>'1',
                'constraint'=>'2',
            ],
I want to display the category content through a datatable and I wrote this query:
$records = $category->select('*')
                ->like('title', $searchValue)
                ->orLike('technical', $searchValue)
                ->orLike('body', $searchValue)
                ->orderBy($columnName, $columnSortOrder)
                ->findAll($rowperpage, $start);
But! As long as the body and technical columns have text data format, it gives an error and does not work, and only when I change their type to varchar does it work.
What should I do to make it work with text type?

Accessing protected property of query object

$
0
0
Is there a way to set the output of getLastQuery() -> finalQueryString to a variable? 
In normal PHP you use the Reflection class, is there a way to access this in CI4?

[CI3] Integrating Altcha

$
0
0
Google is moving recaptcha again requiring changes so I figured what better time to look for alternatives that ideally can be run locally. It seems Altcha fits that quite well, but there exists not a lot of information on how to integrate it beyond throwing composer or something at the problem. The captcha part itself doesn't seem that complex to implement, but the validation side has me rather confused.
https://github.com/altcha-org/altcha-lib-php
https://github.com/altcha-org/altcha-starter-php

Has anyone used this before?
Am I wasting my time here when a solution for self-hosted captcha already exists?

My CI4 powered web starter kit

$
0
0
First of all,
I'm not trying to market my product here. If the admins think otherwise, please feel free to remove this post.

I need your advice!

I've developed a web starter kit for CodeIgniter developers. I previously built a similar tool for CI3, but this is a brand-new version, specifically designed for CI4.x from the ground up.

Please check out the demo version and documentation when you have some spare time.

I’d love your honest feedback why wouldn't you invest in this solution? Is it missing key features? Is the design or architecture not good enough?

Feel free to be brutally honest I appreciate honesty over sugarcoating.

Demo: https://appskull.nudasoft.com/en/auth?ne...sOFt/users
Docs: https://docs.nudasoft.com/appskull/
Thanks!
Viewing all 14343 articles
Browse latest View live


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