Welcome Guest, Not a member yet? Register   Sign In
How to add data when loading CI4 library
#1

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
Reply
#2

https://codeigniter.com/user_guide/insta...pload.html
https://codeigniter.com/user_guide/libra...files.html
https://codeigniter.com/user_guide/libraries/files.html
michalsn.dev - mostly about CodeIgniter
Reply
#3

(04-05-2025, 06:20 AM)michalsn Wrote: https://codeigniter.com/user_guide/insta...pload.html
https://codeigniter.com/user_guide/libra...files.html
https://codeigniter.com/user_guide/libraries/files.html

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

What is the meaning of three dots (...) in PHP?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

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/conce...vices.html

If that again not what you're asking for, I'm afraid you have to explain the question better.
michalsn.dev - mostly about CodeIgniter
Reply
#6

(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/conce...vices.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!)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB