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

Why is where() call different on model to builder?

$
0
0
I am slightly confused as to why the following calls will work when `$lUse` is a builder() object but won't work when its a Codeigniter model??
PHP Code:
$lUse->where("DATE('{$info['Format']}') BETWEEN `From` AND `To`");
$lUse->where(new RawSql("DATE('{$info['Format']}') BETWEEN `From` AND `To`")); 
(And yes for the security conscious I am checking the format of $info['Format']!)
The solution for the Model version is 
PHP Code:
$lUse->where('From >= ',$info['Format']);
 
$lUse->where('To <=',$info['Format']); 
Am I missing something here? Interesting I am using
PHP Code:
clone 
to clone a DB call (I could use Prepared queries but decided against because I'd struggle with parsing in the date for BETWEEN) but when I run these calls on the uncloned (first) instance - it works fine. Perhaps the CI Model is not uber clonable?

Mastering Docker: Simplified Guide for Developers

How to Get Started with Bash Scripting for Automation

Help parsing the log files

$
0
0
Hi,
We're using the standard CodeIgniter log_message() function to log things into ./writable/logs. So far so good, all great. 

What I'd like to do is parse those files once a day and do something with the entries.  So I have to be able to take the log file and parse out each entry. Anyone know of a good way to do that?  The problem I'm seeing is that there's no really good way to differentiate the individual entries because the message itself could be anything. If I have an entry like this:

Code:
ERROR - 2025-01-10 12:34:50 --> There was an error.
My application experienced level/date:  ERROR - 2025-01-10 12:34:50 --> while the user was trying to 
do something.


I said some other thing, but 
the silly user didn't listen.
So I can't split on \n because there will be \n in the message.  The message could even have the words `ERROR - 2025-01-10 12:34:50 -->` in it, so I can't really split it on that.

The problem is that I have multiple applications, 10+, using CodeIgniter and I'd like my parser to be able to iterate through an array of log locations and get the info, all without changing any exising code.

I know I could do something like add a custom error logger (monolog seems the favorite) or write my own, but then I'd have to touch all of those apps. And I'm really trying to avoid doing that. I'm looking for something like awstats for http logs that I can just drop into its own directory and configure it with the location of the logs to parse.

The only other solution would be to use $log = file_get_contents('logfile.log') and get the file as a string. Then do a regex for something like /\n[ERROR|INFO|DEBUG] - \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d -->/g  a newline character followed by one of the 8 levels followed by the date, time and -->.  That's a little painful, especially if there's a better solution.

Any ideas?

Prevent double insert at same time

$
0
0
Hi , today i check if there are some record inserted at same time in  a db's table and i have 21 record duplicated 8 on 2022, 12 on 2023 and 1 on 2024 .I   reduce this effect by adding a js working when i push submit button (disabling button and showing a gif)  at half of 2024 but i have  a duplicate on december 2024 . 

How can I completely avoid this problem?

CodeIgniter 4 Shield - how to override login error message

$
0
0
Hello,
I would like to override the message "Unable to log you in. Please check your password." in the Shield login form. Please don't tell me use your own Validation file" etc. I know how to override other error messages ( wrong email for example ), but I do not know how to override this one. I don't know what to put in the errors array for this error message to work as a override of the original message. 
Thanks.

using services to create an ACL system

$
0
0
Hello!
I am writing an app in which users can create a report object stored in a database. The access (view and edit) to these reports by the author and certain other users is dynamic and needs to be evaluated every time a report is accessed. Shield Auth groups are not dynamic enough to manage report-level ACLs.

The correct way to handle this seems to be a service or a helper that gets called in the controller methods that would load a report for viewing or editing or a list of reports the user can access. Since controllers methods are loaded statically by the router, I'm unsure how or where the best place is to have this ACL check.

Should I write a class to be a shared-instance as a service or a simpler helper? This component will need to access the database to return the ACL. Should an ACL be determined on the fly or stored in a table (it's only ever a few users)?

Thanks for the help!
Evan

How to override Auth.php in vendor/codeigniter4/shield/src/Language/en/

$
0
0
Hello,

My question is really simple, and it's basically contained within a title subject of this thread. So the question is How do I override the stuff in Auth.php file in Shield vendor/codeigniter4/shield/src/Language/en/ folder?

Run command in command is posible ?

$
0
0
Hi
Is posible run command in other command ?

PHP Code:
    public function run(array $params)
    {
        Commands('make:aaa');
    

sapi_windows_vt100_support

$
0
0
Hi
When I try to run the command in the controller, I get this error. Am I doing something wrong, or is it a bug?

PHP Code:
<?php
namespace App\Controllers;
class 
CronController extends BaseController
{
    public function tasks()
    {
      echo  command('start:action cron');
    }


Code:
TypeError
sapi_windows_vt100_support(): Argument #1 ($stream) must be of type resource, string given
SYSTEMPATH\CLI\CLI.php at line 689

Improve ContentSecurityPolicy (CSP)

$
0
0
The way CodeIgniter sets CSP headers means they don't affect static resources like css and js and font files. I don't believe it is possible to add CSP for these resources in httpd.conf without overriding the CodeIgniters CSP settings.

Will setting CSP headers in a filter apply to static resources? Tomcat/Java is able to do this.

I'm guessing this is not possible or feasible with PHP. Therefore I believe the content security policy stuff in CodeIgniter should be removed because it is half assed.

httpd.conf is the proper place to set up CSP in a PHP app. It does not work in PHP code.

debug_on() and debug_off() CI4 equivalent?

$
0
0
Hello,
I'm doing a large CI3 to CI4 migration and came across the following code.  I don't see debug_on() or debug_off() in the CI3 documentation.  Can anyone tell me what that was doing, and if there is an equivalent CI4 implementation?
Thank you!
PHP Code:
                $this->db->debug_off();
                //some db updates
                $this->db->debug_on(); 

Vue or React

$
0
0
Which would you use as a UI with CodeIgniter (Vue or React)?

PHP 8.4.3. This is a bug fix release.

$
0
0
PHP 8.4.3. This is a bug fix release.

point of reputation removed by someone not involved in thread

$
0
0
if   those who  instigated a thread did not appreciate  a post ; i could understand a point being removed from my reputation but do others think it fair or responsible to have a point removed by someone  not even involved in  a thread ?

Limit functionality now working with query builder

$
0
0
Hello All. Have a look at tbe below code and let me know where i am wrong. The Limit is not working. Instead of 10 Rows it returns all the rows in the table. I have logged the $page and $size parameters and they are passed to this function correctly. 
public function listInventoryItems($page, $size, $sorts, $columnFilters, $globalFilter)
{

    $db = db_connect();
    $totalRecords = $db->table('inventory_item')->countAll();

    $builder = $db->table('inventory_item');

      // Select specific columns
     $builder->select([
                          'inventory_item.id',
                          'inventory_item.inventory_unit_of_measure',
                          'inventory_item.inventory_item_category',
                          'inventory_item.inventory_item_type',
                          'inventory_item.code',
                          'inventory_item.name',
                          'inventory_item.reorder_level',
                          'inventory_item.description',
                          'inventory_item.for_sale',
                          'inventory_item.to_be_portioned',
                          'inventory_item.portioned_from_inventory_item',
                          'inventory_item.portion_unit_of_measure',
                          'inventory_item.portion_quantity',
                          'inventory_item.item_picture',
                          'inventory_item.active',
                          'inventory_item.created_at',
                          'inventory_item.created_by',
                          'inventory_item.updated_at',
                          'inventory_item.updated_by'
                          ]);

        // Add LEFT JOIN clauses
        $builder->join('inventory_unit_of_measure', 'inventory_item.inventory_unit_of_measure = inventory_unit_of_measure.id', 'left');
        $builder->join('inventory_item_category', 'inventory_item.inventory_item_category = inventory_item_category.id', 'left');
        $builder->join('inventory_item_type', 'inventory_item.inventory_item_type = inventory_item_type.id', 'left');

        //Global Search
        if ($globalFilter != "") {
            $builder->groupStart()
                ->like('inventory_item.code',$globalFilter)
                ->orLike('inventory_item.name',$globalFilter)
                ->orLike('inventory_item.reorder_level',$globalFilter)
                ->orLike('inventory_item.description',$globalFilter)
                ->orLike('inventory_unit_of_measure.name',$globalFilter)
                ->orLike('inventory_item_category.name',$globalFilter)
                ->orLike('inventory_item_type.name',$globalFilter)
                ->groupEnd();
        }

      // Add ORDER BY clause for multiple fields
        if (isset($sorts) && count($sorts) > 0) {
            $direction = array();
            foreach ($sorts as $sort) {
                $builder->orderBy($sort->key, $sort->direction);
            }
        }

        // Add LIMIT
        if ($page >= 0 && $size > 0) {

            $offset= ($page) * $size;
            $builder->limit($size, $offset); //Per page,Offset
        }
          
        $finalQuery = $builder->getCompiledSelect();
        
        // Execute the query and get the result
       $rows = $builder->get();
       $records = $query->getResultArray(); 
       $filteredRecords = count($records); 
       $db->close();
}
###########################################################

The final query prints as

SELECT `inventory_item`.`id`, `inventory_item`.`inventory_unit_of_measure`, `inventory_item`.`inventory_item_category`, `inventory_item`.`inventory_item_type`, `inventory_item`.`code`, `inventory_item`.`name`, `inventory_item`.`reorder_level`, `inventory_item`.`description`, `inventory_item`.`for_sale`, `inventory_item`.`to_be_portioned`, `inventory_item`.`portioned_from_inventory_item`, `inventory_item`.`portion_unit_of_measure`, `inventory_item`.`portion_quantity`, `inventory_item`.`item_picture`, `inventory_item`.`active`, `inventory_item`.`created_at`, `inventory_item`.`created_by`, 
`inventory_item`.`updated_at`, `inventory_item`.`updated_by`
FROM `inventory_item`
LEFT JOIN `inventory_unit_of_measure` ON `inventory_item`.`inventory_unit_of_measure` = `inventory_unit_of_measure`.`id`
LEFT JOIN `inventory_item_category` ON `inventory_item`.`inventory_item_category` = `inventory_item_category`.`id`
LEFT JOIN `inventory_item_type` ON `inventory_item`.`inventory_item_type` = `inventory_item_type`.`id`
LIMIT 10

But it returns all the records. If Copy and paste this on Mysql it returms 10 rows only.  How ever if  i use get($size,$offset) it works.

if ($page >= 0 && $size > 0) {
            $offset = ($page) * $size;
            $rows = $builder->get($size,$offset);
}
else
{
   $rows = $builder->get();
}


It would be good if i could do it with limit. Kindly help.

PHPUnit test $obj = new ProgTestClass() don't craate controller's object

$
0
0
Hi All

I'm writing a small test and I want to check the value of a property after calling initController

PHP Code:
      $obj = new \App\Controllers\Prog();
      $this->assertTrue$obj->baseOK ); 

Unfortunately, after running the tests I get the following message:
1) App\Controllers\ProgTest::testinitController
Error: Cannot access protected property App\Controllers\Prog::$baseOK

I am using CI4 and phpunit PHPUnit 10.5.41
Thank you in advance for all replies

CodeIgniter v4.5.8 security fix released

$
0
0
We are happy to announce the immediate availability of v4.5.8. This is a security fix and the last patch version for the v4.5 series.
  • Users are strongly advised to upgrade to this version immediately. This patch fixes a security vulnerability where lack of proper validation of a header's name and value can lead to a possible Denial of Service (DoS) scenario. Please refer to the security advisory for more information.
  • This will be the last patch release for the v4.5 series. We'll be releasing the next minor version in the next hour.

    IMPORTANT FOR COMPOSER USERS:  It is anticipated that v4.6.0 release will be bringing possible breaking changes in your applications. To ensure a smooth transition from v4.5 to v4.6, we highly suggest the following tweaks in your composer.json in the require field:

    Code:
    "codeigniter4/framework": "~4.5.7"

    With this change, it is ensured that you will only receive the patch updates. Once v4.6.0 is released and you have followed the upgrade guide, you can now safely change your composer.json back to its original form.

Changelog: https://github.com/codeigniter4/CodeIgni...v4.5.8.rst
Upgrading: https://github.com/codeigniter4/CodeIgni...de_458.rst

CodeIgniter v4.6.0 released!

$
0
0
We are pleased to announce the immediate availability of the latest minor version release: v4.6.0!
This release contains potential breaking changes, a lot of enhancements and new features, and bug fixes. This minor version also has full support of PHP 8.4.

phpunit : gap in the migration sequence

$
0
0
Hello everyone,
I started using migration, I did not use it before. After one migration, my tests with phpunit do not run anyway. This is the message :
Quote:RuntimeException: There is a gap in the migration sequence near version number:  2025-01-14-080346

I just create and run 1 migration but I deleted a file where the up and down functions were empty (I wanted to test the functions and options migrate).

A "migrate refresh" does same error.

Any idea to repair migration process ?

In advance, I thank you.

edit:
I recreate an empty file, ajust table "migrations" via sql (not sure this is the most save method). Tests run OK, but if I run "php spark migrate:refresh", I get :
Quote:There is a gap in the migration sequence near version number: 2020-02-22-222222

(due to an example file tests/_support/Database/Migrations/2020-02-22-2222222_example_migration.php)

Any idea to solve it. I want to have a proper config. In advance, I thank you.
Viewing all 14343 articles
Browse latest View live


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