Welcome Guest, Not a member yet? Register   Sign In
  Depractaion request warning
Posted by: chxgbx - 04-19-2024, 05:52 AM - Replies (2)

I am queite new to codeigniter and having some issues with the request object.

I am trying to pass some tokens from before filter to the request object but getting some depracation warning when trying to access it from controller

```
// before filter
$request->decodedToken = $decoded;
```
```
// after filter
   public function logout()
   {
       $originalToken = $this->request->originalToken ?? null;
   }

```

WARNING - 2024-04-19 12:40:09 --> [DEPRECATED] Creation of dynamic property CodeIgniter\HTTP\IncomingRequest::$originalToken is deprecated in APPPATH/Filters/AuthFilter.php


  Type error in SYSTEMPATH\View\Cells\Cell.php at line 88
Posted by: DXArc - 04-19-2024, 04:08 AM - Replies (4)

I got a type error in SYSTEMPATH\View\Cells\Cell.php at line 88:
substr(): Argument #3 ($length) must be of type ?int, bool given
because of
declare(strict_types=1);
I changed the code to:
            $pos = strrpos($viewName, '_cell');
            if ($pos === false) {
              $possibleView1 = $directory . $viewName . '.php';             
            } else {
              $possibleView1 = $directory . substr($viewName, 0, $pos) . '.php';
            }

Now the gallery using Cell.php is working. I hope it helps.


  Random 403 in Checkout with CI3
Posted by: z72diego - 04-18-2024, 05:48 PM - Replies (2)

Hello everyone!

I gave up trying to solve it on my own, which is why I find myself here asking for help.

I run an online store based on CodeIgniter 3, which randomly (I think, since I was never able to reproduce the error) returns a POST 403 error specifically in the form that leads to the /checkout controller.

It is a problem, since errors are seen by users and are possible sales that may not be made. 

I have my suspicions on the CSRF. I previously suspected CloudFlare, but after some tests I have ruled it out.

Any suggestions?

Thank you so much!


  Webhooks and WebSockets
Posted by: InsiteFX - 04-18-2024, 10:39 AM - No Replies

Dev.to - Webhooks and WebSockets


  TypeError when trying to use MemcachedHandler for sessions
Posted by: b126 - 04-18-2024, 06:26 AM - Replies (3)

I am trying to use MemcachedHandler for my sessions.
I have thus these two lines in Config\Session.php:

PHP Code:
    public string $driver MemcachedHandler::class;
    public string $savePath 'localhost:11211'


I get the following error :

Quote:TypeError

CodeIgniter\Cache\Handlers\MemcachedHandler::__construct(): Argument #1 ($config) must be of type Config\Cache, Config\App given, called in C:\wamp64\www\project\vendor\codeigniter4\framework\system\Config\Services.php on line 667


  Retaining search variables to return to filtered view
Posted by: pchriley - 04-18-2024, 05:46 AM - Replies (2)

Hello,
My document management system opens by default to a paged table showing all rows in the documents table.  
Controller:

PHP Code:
public function index(){
        $documentModel = new DocumentModel();
        $db = \Config\Database::connect();
        $queryStatus $db->query("SELECT * FROM dms_status");
        $queryCategory $db->query("SELECT * FROM dms_category");
        $queryDoctype $db->query("SELECT * FROM dms_doctype");
$data = [
 
'dms_documents' => $documentModel->orderBy('subject DESC, document_date')->findAll(),
 
'statusShow' => $queryStatus->getResultArray(),
 
'categoryShow' => $queryCategory->getResultArray(),
 
'doctypeShow' => $queryDoctype->getResultArray(),
 ];
    return view('pages/document_table_view'$data);
    

View:
PHP Code:
<?php if($dms_documents): ?>
                            <?php foreach($dms_documents as $dms_document): ?>
                            <tr>
                            <td><?php echo $dms_document['subject']; ?></td> 
<td><a href="<?php echo base_url('document-edit-form/'.$dms_document['docID']);?>"</a><?php echo $dms_document['description']; ?></td> 
                       

The 'Description' column for each row is an href link to that record, and opens - routed via the Controller - an edit form for that record.  The edit form allows me to amend/save, ignore or delete the record.  The edit form action then returns me to the original table view.
That all works fine, but I've now introduced a search form so that the resulting version of the table view is filtered according to the search criteria (currently just a simple 'LIKE'):

PHP Code:
[code]$data = [
            'field' => $this->request->getVar('field'),
            'searchtext' => $this->request->getVar('searchtext'),
            ];
        
        $documentModel 
= new DocumentModel();
    $db = \Config\Database::connect();
    $builder $db->table('dms_documents');
        $queryStatus $db->query("SELECT * FROM dms_status");
        $queryCategory $db->query("SELECT * FROM dms_category");
        $queryDoctype $db->query("SELECT * FROM dms_doctype");
        
        $builder
->like($data['field'], $data['searchtext'], 'both');
        $results $builder->get();
    
        $filterData 
= [
        'filter_validation' => $this->validator,
        'filter_dms_documents' => $results->getResultArray(),
        'filter_statusShow' => $queryStatus->getResultArray(),
        'filter_doctypeShow' => $queryDoctype->getResultArray(),
      'filter_categoryShow' => $queryCategory->getResultArray(),
        'filterText' => $query,
        'isFiltered' => TRUE,
        ];
        
        
return view('pages/document_table_view_filter'$filterData);[/code

This works, but what I cannot fathom out is how to return from the edit form to a table view reflecting the search criteria (also taking into account any changes made via the edit form) rather than to the full dataset.  
Thanks


  Reading a session variable in CI3 that was set by CI4
Posted by: xanabobana - 04-17-2024, 11:53 AM - Replies (4)

Hello-  I am working on a large migration from CI3 to CI4.  I have attempted to set the session $savePath and $cookieName to be the same in CI3 and CI4, so that I can read in CI3 a session variable that is set by CI4.  My example is that I have a CI4 page which requires login.  It sets a session variable 'destination' with the URL to redirect to after logging in, then redirects (using a route) to the CI3 login page.  However, once there I am not able to retrieve that session variable.  I'm not sure what I am missing.
I changed app\Config\Session.php to have: 

Code:
    public string $cookieName = 'ci_session';
    public string $savePath = 'ci_sessions_CI3'; 
I confirmed that in CI3 application\config\config.php says:
Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions_CI3';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;

My code in CI4 (app\Controllers\Manage\Admin.php)
Code:
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) {
        parent::initController($request, $response, $logger);
       
        $this->session = session();         
        $this->db = db_connect();
               
        //Check if this is being run via command line
        if (!$this->request->isCLI()){
            //a user must be logged in to go here so check if they are logged in and are an admin
            if(!$this->ionAuth->loggedIn()){   
                $this->session->set('message', 'Please log in to manage projects');
                $this->session->set('url', current_url()); 
                $this->session->set('destination', current_url());
                // use header because CI4 redirect needs to return and can't return in initController
                header("Location: " . site_url('auth/login'));
                exit;               
            }
            if (!$this->ionAuth->isAdmin()){
                show_404();
            }
        }       
    }

There is a route from auth/login that redirects to CI3 (application\controllers\Users.php). My CI3 code there looks like:  
Code:
        if($this->session->userdata('destination')!=""){
            $this->session->set_flashdata('destination',$this->session->userdata('destination'));
        }
        else{//If not, then just send them to profile management splash page on successful login
            $this->session->set_flashdata('destination',site_url('manage'));
        }
        redirect($this->session->flashdata('destination'), 'refresh');

The above code keeps redirecting me to site_url('manage').  
What am I missing to set the session var in CI4 and read it in CI3?  
Any help is appreciated, let me know if you have more questions.  Thank you!


  Update to v4.5.1, same using FactoriesCache
Posted by: ddevsr - 04-17-2024, 07:39 AM - Replies (5)

I updated from 4.4.x to 4.51, Follow instruction upgrading. I clear cache first created by 4.4.x, and open again in browser with local computer give SUCCESS. But with environment dev server same as clear cache first appear ERROR

Fatal error: Declaration of CodeIgniter\Log\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with PsrExt\Log\LoggerInterface::emergency($message, array $context = []) in /home/http8_data/xxx/vendor/codeigniter4/framework/system/Log/Logger.php on line 162

This is related to FactoriesCache? What a problem?


  Showing pdf on browser
Posted by: aarefi - 04-15-2024, 02:53 PM - Replies (3)

I need a way to show a pdf file on browser in codeignter v4.4.0 or later. I have tried inline method in download response but it always downloads the pdf file.

$this->response->download(.......)->inline();

even setting headers have not helped

return $this->response
            ->setHeader('Pragma','public')
            ->setHeader('Expires','0')
            ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
            ->setHeader('Content-Disposition','inline; filename="'.$filename.'"')
            ->setContentType('application/pdf')
            ->setHeader('Content-Length',strlen($data))
            ->download($filename,$data,true);

Would you please help me?


  blocked by CORS policy
Posted by: lucascortes - 04-15-2024, 01:00 PM - Replies (1)

I created a restful api with codeigniter 4, but when I make a request through the browser, I get the following error: "Access to XMLHttpRequest at 'http://localhost:3001/v1/pessoa' from origin 'http:// localhost:8080' 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.".
But when I test it through postman, it works correctly.
What should be done to correct it? I already tried to create a filter, as suggested on the internet, but it didn't work.
In the frontend I make a request and in the network tab of devtools, two requests appear, one is Options and it was giving 404, so I created a method in my control and defined this route to Options, so this first option responded ok, but the GET method continues 404 (GET + preflight), how do I resolve this situation, someone please help me.


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

Username
  

Password
  





Latest Threads
Is it possible to go back...
by ejimenezo
1 hour ago
Error / Shield 1.0.3 + Ci...
by kcs
5 hours ago
SQL server connection not...
by davis.lasis
6 hours ago
Validation | trim causes ...
by Gary
8 hours ago
Problem with session hand...
by Julesb
9 hours ago
External script access to...
by PomaryLinea
9 hours ago
VIRUS reported after Chro...
by InsiteFX
Yesterday, 11:34 PM
Codeigniter4 version 4.5....
by kenjis
Yesterday, 04:10 PM
Cannot access protected p...
by xsPurX
Yesterday, 02:10 PM
Update to v4.5.1, same us...
by xsPurX
Yesterday, 08:31 AM

Forum Statistics
» Members: 85,492
» Latest member: Cityboybiz
» Forum threads: 77,583
» Forum posts: 376,018

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB