Welcome Guest, Not a member yet? Register   Sign In
  Variables question
Posted by: Huisache - 4 hours ago - Replies (2)

Hi to everybody! I need to change the 'defaultLocale' var from a controller, in codeigniter 3 I could do that simply with this line:

$this->config->set_item('language', $lang);

But in Codeigniter4 if try to do this:

config('Config\\App')->defaultLocale = $lang;

The value of the global config don't change...

How can i do this? With the function config() i'm accessing to the global config or to a new instance of config?

Thx!


  Simple Introduction To HTMX
Posted by: InsiteFX - Yesterday, 11:31 AM - No Replies

Simple Introduction To HTMX


  Full Logs text
Posted by: motoroller - 03-17-2024, 12:30 PM - Replies (3)

Stack trace:
#0 /var/www/www-root/data/www/vetaf.ru/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php(306): mysqli->query('INSERT INTO `or...', 0)
#1 /var/www/www-root/data/www/vetaf.ru/vendor/codeigniter4/framework/system/Database/BaseConnection.php(693): CodeIgniter\Database\MySQLi\Connection->execute('INSERT INTO `or...')
#2 /var/www/www-root/data/www/vetaf.ru/vendor/codeigniter4/framework/system/Database/BaseConnection.php(607): CodeIgniter\Database\BaseConnection->simpleQuery('INSERT INTO `or...')
#3 /var/www/www-root/data/www/vetaf.ru/vendor/codeigniter4/framework/system/Database/BaseBuilder.php(2307): CodeIgniter\Database\BaseConnection->query('INSERT INTO `or...', Array, false)

how can i see full query?


  How to trigger and listen to events with class-based methods in a cool way
Posted by: agungsugiarto - 03-16-2024, 09:46 PM - Replies (1)

[Image: 9TuDbCp.png]

https://gist.github.com/agungsugiarto/6e...7b158f0529


  Shield 1.0.2
Posted by: kenjis - 03-16-2024, 09:05 PM - Replies (1)

The bug fix 1.0.2 has been released!
It also includes Dutch (nl) translations.

See release note for details.


  POTENTIAL BUG querybuilder-save not working as intented
Posted by: ramonpuig - 03-15-2024, 06:32 AM - Replies (1)

Hi i have observed that with version 4.4.6 the save() method does not insert a row even if the primarykey value is not found in the row . I believe there might be a bug .

The save operation returns true and the parent-s Model save method chooses to update instead of insert.

The sql log shows the operation was completed

  593 Query UPDATE `UserMatches` SET `userA_ID` = '87', `userB_ID` = '65', `Score_Cn` = 12, `Score_My` = 0, `Score_Zd` = 0, `Score_Hd` = 0, `Score_Num` = 0
WHERE `UserMatches`.`matchID` IN ('87_65')
  593 Query SELECT *
FROM `UserAstroInfo`
WHERE `userID` = '87'


So its the CI4 method choosing to update instead of insert, because the matchID '87_65' is not present, I triple checked.

Also in the model the primarykey is correct .



I had to replace the save method by an alternative and it works now.


  PHP 8.3.4. This is a bug fix release.
Posted by: InsiteFX - 03-15-2024, 05:15 AM - No Replies

PHP 8.3.4. This is a bug fix release.


Shocked Cors policy filter not work
Posted by: alakian - 03-15-2024, 02:34 AM - Replies (4)

I make a filter to fix CORS Policy errors:

CorsFilter.php:

PHP Code:
namespace App\Filters;

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

class 
CorsFilter implements FilterInterface
{
    public function before(RequestInterface $request$arguments null)
    {

        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS");
        header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
        header('Content-Type: application/json');
        $method $_SERVER['REQUEST_METHOD'];
        if ($method == "OPTIONS") {
            header('Access-Control-Allow-Origin: *');
            header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
            header("HTTP/1.1 200 OK");
            die();
        }

    }

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


Filters.php
PHP Code:
    public array $aliases = [
        'csrf'          => CSRF::class,
        'toolbar'      => DebugToolbar::class,
        'honeypot'      => Honeypot::class,
        'invalidchars'  => InvalidChars::class,
        'secureheaders' => SecureHeaders::class,
        'cors'          => CorsFilter::class //Add
    ];

    public array $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
            // 'invalidchars',
            'cors' //Add
        ],
        'after' => [
            'toolbar',
            // 'honeypot',
            // 'secureheaders',
        ],
    ]; 

Routes.php:
PHP Code:
$routes->post('api/login''Api\Auth\LoginController::jwtLogin', ['filter' => 'cors']); 


Now in action CorsFilter Doesn't work and I've faced with this error:


Code:
Access to XMLHttpRequest at 'http://api/auth/jwt' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Just For Test: I put my code in index.php and surprisingly, this worked truly and fix CORS policy errors.

How to create a filter to fix CORS policy errors?!


  Cant display user-image in AdminLTE header
Posted by: jakeneuman - 03-15-2024, 01:52 AM - No Replies

Good day, im new in codeigniter but im enjoying it with integretion of Admin LTE. So far so smooth when I started making a system but lately i've got some problems with ta header of the AdminLTE theme. The use profile image won't display but in dashboard it will display ... can anyone enlighten me on this, am i missing something?
this is my code:

PHP Code:
      <!-- Sidebar user panel -->
      <div class="user-panel">
        <div class="pull-left image">
        <?php 
          
if(isset($staff)){
              $userid $this->session->userdata('userid');
                foreach ($staff as $stff):
                  if ($stff['id'] == $userid){ ?>
                    <img src="<?php echo base_url();?>uploads/profile-pic/<?php echo $stff['pic'];?>" class="img-circle" alt="User Image">
                <?php  }
                endforeach;
            }
        ?> 
        </div>
        <div class="pull-left info">
          <p>Staff Account</p> 
          <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
        </div>
      </div> 
 
this code will work on dashboard page but not in header page.
thanks in advance..


  Model with session only and without database
Posted by: StefanKittel - 03-14-2024, 02:24 PM - Replies (2)

Hello,
I want to create one model with session only and without database.

The other models are needed for database operations.

The model should handle some informations in the session.

I think a model is more suitable than a controller

I remove everything in the model but a soon I call a function in it I get an error: "You must set the database table to be used with your query.".

I don't need any type of data behind this model.
I could put it in a controller and would be done. But it is wrong there.

So how to remove the database for this model only?

PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
StateModel extends Model
{
    public function Init()
    {
        // Preload any models, libraries, etc, here.
        if (!isset($this->session))
        {
            $this->session = \Config\Services::session();
        }
    }

    public function GetLoginState()
    {
        return NO_SITE_SET;
    }


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Variables question
by InsiteFX
32 minutes ago
Weird CI4 issue where the...
by hvn2k
2 hours ago
CI4 Newbie, no log files ...
by xanabobana
Yesterday, 11:45 AM
Simple Introduction To HT...
by InsiteFX
Yesterday, 11:31 AM
Full Logs text
by motoroller
Yesterday, 01:27 AM
CORS Issue with Codeignit...
by kenjis
Yesterday, 12:24 AM
Cors policy filter not wo...
by kenjis
03-17-2024, 10:33 PM
How to trigger and listen...
by datamweb
03-17-2024, 08:52 AM
Shield 1.0.2
by InsiteFX
03-17-2024, 01:46 AM
POTENTIAL BUG querybuilde...
by kenjis
03-15-2024, 06:31 PM

Forum Statistics
» Members: 81,326
» Latest member: aspir4x4
» Forum threads: 77,439
» Forum posts: 375,350

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB