Welcome Guest, Not a member yet? Register   Sign In
Model files in CI4
#16

OK for the Model file, thanks.
But I still have some doubt on controller and libraries (the part that handles the model):

Previous version, in CI3, was:
File Home.php:
PHP Code:
// nothing on header

public function __construct()
{
 parent::__construct();
 $this->load->model('mymodel01');
}

public function 
index()
{
 $tableA $this->mymodel01->read_file_aaaa();
 ...



File Library01.php:
PHP Code:
class Library01
{
 protected $CI;
 public function __construct()
 {$this->CI =& get_instance();}

 public function some_subroutine()
 {
  $tableB $this->CI->mymodel01->read_file_bbbb();
  ...
 }

My new version, in CI4, is:
Home.php:
PHP Code:
use App\Models\Mymodel01;

class 
Home extends BaseController
{
 public function __construct()
 {static $G_Mymodel01;}

 public function index()
 {
  global $G_Mymodel01;
  $G_Mymodel01 = new \App\Models\Mymodel01();
  ...
  $tableA $G_Mymodel01->read_file_aaaa();
  ...
 }

Library01.php:
PHP Code:
use ??? // not yet checked

class Library01
{
 public function some_subroutine()
 {
  global $G_Mymodel01;
  ...
  $tableB $G_Mymodel01->read_file_bbbb();
  ...
 }


Is this correct?
I mean: it works (at least the controller; library not yet checked), but in this new version I have more code lines to write, instead of less. Maybe is there some "trick" that I haven't yet found?
Reply


Messages In This Thread
Model files in CI4 - by Filippo65 - 07-06-2021, 10:39 AM
RE: Model files in CI4 - by MGatner - 07-07-2021, 06:14 AM
RE: Model files in CI4 - by paliz - 07-07-2021, 09:17 AM
RE: Model files in CI4 - by Filippo65 - 07-12-2021, 10:06 AM
RE: Model files in CI4 - by includebeer - 07-12-2021, 03:44 PM
RE: Model files in CI4 - by InsiteFX - 07-12-2021, 09:04 PM
RE: Model files in CI4 - by davis.lasis - 07-13-2021, 03:29 AM
RE: Model files in CI4 - by Filippo65 - 07-14-2021, 11:18 AM
RE: Model files in CI4 - by includebeer - 07-14-2021, 02:23 PM
RE: Model files in CI4 - by Filippo65 - 07-19-2021, 10:57 AM
RE: Model files in CI4 - by includebeer - 07-19-2021, 02:45 PM
RE: Model files in CI4 - by Filippo65 - 07-20-2021, 10:52 AM
RE: Model files in CI4 - by Filippo65 - 07-20-2021, 12:47 PM
RE: Model files in CI4 - by Filippo65 - 07-21-2021, 10:30 AM
RE: Model files in CI4 - by includebeer - 07-23-2021, 04:52 AM
Model files in CI4 - by Filippo65 - 08-20-2021, 09:28 AM
RE: Model files in CI4 - by ikesela - 08-20-2021, 12:50 PM
RE: Model files in CI4 - by includebeer - 09-05-2021, 03:39 PM
RE: Model files in CI4 - by Filippo65 - 09-23-2021, 07:44 AM
RE: Model files in CI4 - by InsiteFX - 09-06-2021, 12:56 AM
RE: Model files in CI4 - by Filippo65 - 09-25-2021, 09:34 AM
RE: Model files in CI4 - by InsiteFX - 09-26-2021, 12:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB