CodeIgniter Forums
loading my own library into helper function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: loading my own library into helper function (/showthread.php?tid=76001)



loading my own library into helper function - igorc - 04-05-2020

Hello.

i have function form()
{
    # there is where i would like to load my library into $form_ variable
 $form_ = service('Form'); <- this doesn't work - my app/libraries/form library
 $timer = service('Timer'); <- this works - ci service
dd($form_);

}

how can i load instance of ci into this helper function?

Second question: I created app/libraries/Form.php library

<?php namespace App\Libraries;

class Form
{
    protected $validation = false;

    public function __construct()
    {
    $this->validation = [];
       
    }

    public function validations()
    {
    $this->validation['peter'] = 'test';
        return $this->validation;
    }

    public function add($name,$rules)
    {
    echo "OKa";
    die;
    $this->validation[$name] = $rules;
    }

}


how can i load this library in my helper function form?


RE: loading my own library into helper function - igorc - 04-05-2020

$validation = new Application\Libraries\Form;
when i try to call it like this, it does not work.