Welcome Guest, Not a member yet? Register   Sign In
How to load in custom library in ci4
#1

I was trying to load custom libraries in ci4 to try and implement smarty with ci4 as we do in ci3 has anyone here try and be succeeded.

If ci4 don't allow me to use smarty template engine I stuck with ci3.
Reply
#2

You should be able to load it, but it will need to be in it's own namespace.

The namespace can then be loaded into CI4 autoloader.

.app/Config/Autoload.php
What did you Try? What did you Get? What did you Expect?

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

(11-01-2019, 08:38 AM)InsiteFX Wrote: You should be able to load it, but it will need to be in it's own namespace.

The namespace can then be loaded into CI4 autoloader.

.app/Config/Autoload.php

I have tried to look into the Autoload.php this the library will be load in Classmao?
Reply
#4

Looks like Smarty is not using namespaces, so you just have to include the file. You could use the Classmap for autoloading and that should work, I think. But, since you'll know where you're storing it in your app, there's no need for that, just include the file as you would any other PHP file.

Per their crash course:

PHP Code:
include('Smarty.class.php');

// create object
$smarty = new Smarty
Reply
#5

https://code4.ru/docs/podklyuchaem-smart...ter-4.html

I wrote this instruction, but on Russian language. Try to use Google-Translate to understand my text. I believe what you understand )) Sorry for my bad English.
Reply
#6

PHP Code:
namespace App\Libraries;

require_once 
APPPATH.'ThirdParty/Smarty/Autoloader.php';

use \
Smarty_Autoloader;

Smarty_Autoloader::register();

use \
Smarty;

class 
Yourclass extends Smarty {


Reply
#7

(02-10-2020, 07:27 PM)x1250 Wrote:
PHP Code:
namespace App\Libraries;

require_once 
APPPATH.'ThirdParty/Smarty/Autoloader.php';

use \
Smarty_Autoloader;

Smarty_Autoloader::register();

use \
Smarty;

class 
Yourclass extends Smarty {


May you remail bless Thank You!
Reply
#8

(This post was last modified: 04-05-2020, 12:37 PM by 404NotFound.)

(11-01-2019, 02:52 AM)seunex Wrote: I was trying to load custom libraries in ci4 to try and implement smarty with ci4 as we do in ci3 has anyone here try and be succeeded.

If ci4 don't allow me to use smarty template engine I stuck with ci3.


I use firebase/php-jwt library with composer
Code:
composer require firebase/php-jwt
Note that when you use composer, your library is put in vendor folder

Then I just load it in my controller:

app/Controllers/MyController.php
PHP Code:
use Firebase\JWT\JWT;
class 
MyController extends Controller {
   public function index() {
      $key 'blablabla';
      $jwt = new JWT();
      $payload = array(
         'iss' => base_url(),
         'name' => 'Hello World'
      );
      $token $jwt->encode($payload$key);
      echo $token;
   }



It's working for me, I hope it helps others too.
It's better in my point of view

   
Reply
#9

(02-09-2020, 10:04 AM)5flex Wrote: https://code4.ru/docs/podklyuchaem-smart...ter-4.html

I wrote this instruction, but on Russian language. Try to use Google-Translate to understand my text. I believe what you understand )) Sorry for my bad English.

Very grateful you shared this. Thanks to Google Translate, I was able to successfully convert an old CI3 library to use with CI4 (Uuid).

Your English is way better than my Russian, so again, thanks so much for sharing. I learned a lot about namespaces and classmaps doing this.

Cheers
Reply




Theme © iAndrew 2016 - Forum software by © MyBB