Hello Experts I am in a big problem I am using emojione library to convert short name to image the emojis works fine when using on code php but i want this to use with codegniter i decided to created a model so i can easily access on al over for that I created a function inside my EmojiModel.php
defined('BASEPATH') OR exit('No direct script access allowed');
class EmojiModel extends CI_Model {
public function __construct() {
parent::__construct();
require APPPATH . 'third_party/emojione/LoadEmojione.php';
}
public function LoadImageEmoji($mojiText) {
$emoji = new \EmojiLoad();
return $emoji->LoadImageEmoji($mojiText);
}
}
inside third party library I hade added the library and created a file named LoadEmoji.php and simply included that file inside model constructor
application\third_party\emojione\LoadEmojione.php
namespace Emojione;
require 'vendor/autoload.php';
class EmojiLoad {
public function LoadImageEmoji($textEmoji) {
$client = new Client(new Ruleset());
$client->imagePathPNG = 'https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/png/';
return $client->toImage($textEmoji);
}
}
The error I am getting is
An uncaught Exception was encountered Type: Error
Message: Class "EmojiLoad" not found
I am not sure what should I do because it is important in this library to use namespace i am confused what should I do here
Change this line
$emoji = new \EmojiLoad();to$emoji = new \Emojione\EmojiLoad();. YourEmojiLoadclass is in theEmojionenamespace, so you need to add the namespace before the classname when using it.Alternatively, as shirshak007 suggested, if you're only using your custom
EmojiLoadclass in theEmojiModelclass, you can also use theEmoijonelibrary directly in the model.In that case I would also suggest using CodeIgniter's
composer_autoloadfunction:In
application/config/config.php, set$config['composer_autoload']toTRUE.This expects the
composer.jsonfile to live in theapplicationfolder, so copy it there from theapplication/third_party/emojionefolder and then delete theapplication/third_party/emojionefolder. If you then docomposer installfrom theapplicationfolder, it'll create a newvendorfolder inside theapplicationfolder.Then use the
Emojionelibrary directly in the model: