Welcome Guest, Not a member yet? Register   Sign In
Converting a CI3 Project to CI4.5.1
#1

(This post was last modified: 05-10-2024, 09:14 PM by Josh1985. Edit Reason: typo in topic )

Hello all!

I have recently sat down with the intention of converting a pretty large CI3 project into CI4. However, I have ran into a few issues that I can't seem to find in the documentation that really specifies what to do in my situation.

Library Conversions:

MyController.php (Custom Controller Library)
PHP Code:
<?php

 
class MyController extends CI_Controller{
  function __construct(){
  parent::__construct();
  $this->load->vars(array('toc' => $this->recipe_model->read_names_categories(),
  'admin_menu_items' => array(),
  'admin' => $this->is_logged_in()));
  if($this->is_logged_in()){
    date_default_timezone_set($this->session->userdata('tz'));
  }
  else{  // If the IF statement returns false, then  the ELSE statement tells php to do something else.
    date_default_timezone_set('America/New_York');
  }
  }
    
  
function is_logged_in(){
  $logged_in $this->session->userdata('logged_in');
  if(isset($logged_in) && $logged_in){
    return true;
  }
  else{  // If the IF statement returns false, then  the ELSE statement tells php to do something else.
    return false;
  }
  }
    
  
function require_login(){
  if(!$this->is_logged_in()){
    redirect('login');
  }
  }
    
  
function format_date($datestr){
  //date_default_timezone_set('UTC');
  $date strtotime($datestr.' UTC');
  //date_default_timezone_set('America/New_York');
  $datestr date("n/j/Y @ g:i A T"$date);
  return $datestr;
  }  
 
}  
 
 
// End of MyController CUSTOM Controller.php
 // End of MyController.php

?>

MySecurity.php (Custom Security Library)
PHP Code:
<?php

 
class MySecurity extends CI_Security {
  
  
/*
  * CSRF Set Cookie with samesite
  *
  * @codeCoverageIgnore
  * @return  CI_Security
  */
  
  
public function csrf_set_cookie(){
  $expire time() + $this->_csrf_expire;
  $secure_cookie = (bool) config_item('cookie_secure');
  if($secure_cookie && ! is_https()){
    return FALSE;
  }
  setcookie($this->_csrf_cookie_name,
            $this->_csrf_hash,
            ['samesite' => 'Strict',
              'secure'  => true,
              'expires'  => $expire,
              'path'    => config_item('cookie_path'),
              'domain'  => config_item('cookie_domain'),
              'httponly' => config_item('cookie_httponly')]);
              
  log_message
('info''CSRF cookie sent');
  return $this;
  }
 }

 
// End of MySecurity CUSTOM Security.php
 // End of MySecurity.php

?>

1. In CI3, this current project had several different custom libraries in use in CI3's application/core, CI3's application/libraries, and CI3's system/libraries directories. My question is here in CI4, I only see one "Libraries" directory in app/Libraries. Is this one location where ALL of my libraries would go? Or do I need to divide them between this directory and put others somewhere else?

2. In CI3, this project had a custom controller and a custom security exception.  So, again where would these files go?

3. I know in CI4, we often use BaseController as our extendable controller base class. The custom controller from CI3 that I am referring to was basically doing something very similar to what the BaseController class does in CI4. So my issue is, do I just add the custom parameters to BaseController or do I add the custom controller class into some special directory?   

Any help would be greatly appreciated!

Thanks
Reply


Messages In This Thread
Converting a CI3 Project to CI4.5.1 - by Josh1985 - 05-10-2024, 07:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB