1

I am new to yii and i have to create a yii component for Enom api .I have followed this url Enom application for refrence . It is in core php and i want to implement this in yii as component or module .I have done in this way

  1. put the files interface and class in the yii component folder.

  2. modify the class as mentioned here yii custom component . Now my class name is EnomService and interface name is EnomInterface i have added these lines also in my class

    use Yii; use yii\base\Component; use yii\base\InvalidConfigException;

  3. modified the main.php file in config folder:

    'import'=>array(
        'application.models.*',
        'application.components.*',
     ),
    
    'defaultController'=>'post',
    
    // application components
    'components'=>array(
        'user'=>array(
            // enable cookie-based authentication
            'allowAutoLogin'=>true,
        ),
        'mycomponent' => [
    
            'class' => 'app\components\EnomService',
    
            ],
    
  4. calling in the controller in this way .

    public function actionEnom () 
    {
         echo "asdgsgsag";
         $enom = new EnomService('manoj_rudra', 'manoj@41@', false, true);
         $enom->debug = true;
         $result=   Yii::$app->EnomService->checkDomain('systurn', 'com', true);
         //$result = $enom->checkDomain('systurn', 'com', true);   // This enables domain spinner
         echo '<pre>';
         var_dump($result);
         echo '</pre>';
    }
    

But it is not working . I am not so much familiar with yii custom component . Please help me to create this .

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68

1 Answers1

0

Are you using Yii or Yii2?

If it is Yii, then you could use plenty of other existing extensions to inspire yourself, for example this one: https://github.com/HeavyDots/yii-sms

As for Yii2 you could do something similar, look into already existing extensions for Yii2 on YiiFramework website and you can see how component classes are defined.

I would recommend:

1) Create a new directory inside "components" named "enom"

2) Place inside that directory all your enom files from https://github.com/comdexxsolutionsllc/MoondayFramework/tree/master/engine/enom

3) Create the component class called "Enom.php" inside the directory, something like this:

<?php

// include enom service class
require(dirname(__FILE__).'/class.EnomService.php'); 

namespace components\enom;
use Yii;

class Enom extends \yii\base\Component
{
    // define private property to store service
    private $service;

    public function init()
    {
        parent::init();

        // init the service
        $this->service=new EnomService('manoj_rudra', 'manoj@41@', false, true);
    }

    /**
      * @return     EnomService
      */
    public function getService() {
        return $this->service;
    }

}

?>

4) Then in the configuration properly define the component

'enom' => [

        'class' => 'app\components\enom\Enom',

        ],

5) And finally use it like this

Yii::$app->enom->getService()->checkDomain

As I said before, haven't used Yii2 yet so this might need tweaking but could point you on the right path.