CodeIgniter Forums
How to add data when loading CI4 library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to add data when loading CI4 library (/showthread.php?tid=92713)



How to add data when loading CI4 library - PaulC - 04-05-2025

Hi Team,
I have had to bite the upgrade bullet. Generally I find the docs excellent, but I have hit a small issue with upgrading a CI3 load->library call which includes an array of parameters
ie
            //Load library
            $config['upload_path'] = $upload_folder;
            $config['allowed_types'] = 'jpeg|jpg|png';
            $config['max_size'] = $max_size * 1024;
            $config['file_name'] = $col.'_'.$row; //Temp name
       
            $this->load->library('upload', $config);
            $this->load->library('image_lib');
I can find no help on this migration.
Can anyone point me in the right direction please or explain what I need to refactor perhaps?
TIA, Paul


RE: How to add data when loading CI4 library - michalsn - 04-05-2025

https://codeigniter.com/user_guide/installation/upgrade_file_upload.html
https://codeigniter.com/user_guide/libraries/uploaded_files.html
https://codeigniter.com/user_guide/libraries/files.html


RE: How to add data when loading CI4 library - PaulC - 04-05-2025

(04-05-2025, 06:20 AM)michalsn Wrote: https://codeigniter.com/user_guide/installation/upgrade_file_upload.html
https://codeigniter.com/user_guide/libraries/uploaded_files.html
https://codeigniter.com/user_guide/libraries/files.html

Terse! My question was nothing to do with file uploads.


RE: How to add data when loading CI4 library - InsiteFX - 04-06-2025

What is the meaning of three dots (...) in PHP?


RE: How to add data when loading CI4 library - michalsn - 04-06-2025

Sorry, I guess I misunderstood your question.
So you have your own library and want to rewrite it to work with CI4?

In that case, instead of
PHP Code:
$this->load->library('whatever'$config); 
you will do
PHP Code:
$whatever = new \App\Libraries\Whatever($config); 

Alternatively, you can also use service to get a single instance every time: https://codeigniter.com/user_guide/concepts/services.html

If that again not what you're asking for, I'm afraid you have to explain the question better.


RE: How to add data when loading CI4 library - PaulC - 04-07-2025

(04-06-2025, 08:38 AM)michalsn Wrote: Sorry, I guess I misunderstood your question.
So you have your own library and want to rewrite it to work with CI4?

In that case, instead of
PHP Code:
$this->load->library('whatever'$config); 
you will do
PHP Code:
$whatever = new \App\Libraries\Whatever($config); 

Alternatively, you can also use service to get a single instance every time: https://codeigniter.com/user_guide/concepts/services.html

If that again not what you're asking for, I'm afraid you have to explain the question better.

Thx, just what I wanted. I suppose the "..." comment was a pointer to unpacking associative arrays (new in php8). From what I have read the keys have to be defined in the constructor for the unpacking to work. (Just in case someone reads this thread in the future!)