0

I am trying to use the Zend Service Livedocx. I am using two models in my application - Submission and SubmissionFiles. I am saving the Submission data and the SubmissionFiles data with the Create action in the SubmissionController. I am trying to call the MailMerge class in that action but I am getting the error: Fatal error: Cannot redeclare class ZendService\LiveDocx\AbstractLiveDocx in C:\wamp\www\publications\src\web\protected\vendors\ZendService\LiveDocx\AbstractLiveDocx.php

SubmissionController

//some code

public function actionCreate()
{
    $model=new Submission;

    if(isset($_POST['Submission']))
    {
        $model->attributes=$_POST['Submission'];
        if($model->save()) 
        {
            $modelFile = new SubmissionFiles;
            if(isset($_POST['SubmissionFiles']))
            {   
            Yii::import('application.vendors.zendservice.livedocx.*');

                $phpLiveDocx = new MailMerge(); 
 //somecode

protected/vendors/ZendService/LiveDocx/MailMerge.php

<?php

require_once 'ZendService\LiveDocx\AbstractLiveDocx.php';

class MailMerge extends AbstractLiveDocx
{ //somecode

protected/vendors/ZendService/LiveDocx/AbstractLiveDocx.php

<?php

namespace ZendService\LiveDocx;

use Traversable;
use Zend\Soap\Client as SoapClient;
use Zend\Stdlib\ArrayUtils;

abstract class AbstractLiveDocx
{ //some code

If I comment the require_once 'ZendService\LiveDocx\AbstractLiveDocx.php'; in MailMerge.php, I get the error: Fatal error: Class 'AbstractLiveDocx' not found in C:\wamp\www\publications\src\web\protected\vendors\ZendService\LiveDocx\MailMerge.php

What am I doing wrong?

Ilia
  • 17
  • 5

1 Answers1

0

I guess you are using composer to include Zend as dependancy. If so you must add the autoloader to your index.php file(or whatever you bootstrap with).

// change the following paths if necessary
require_once(dirname(__FILE__).'/../vendor/autoload.php');

After that replace the require_once line with:

use ZendService\LiveDocx\AbstractLiveDocx;

Hope that works :)

Nikola
  • 493
  • 4
  • 12
  • I read that I can just paste the zendservice folder in vendors and then use the class with **Yii::import('application.vendors.zendservice.livedocx.*');**. I don't have an autoloader file. – Ilia Apr 04 '14 at 11:30
  • I really recommend using composer and its autoloader since this file may require other dependencies that will result in this error. – Nikola Apr 04 '14 at 11:33
  • Okay, I downloaded yiiframework.com/extension/zendautoloader and included require_once(dirname(__FILE__).'/protected/extensions/zend-autoloader-component/E‌​ZendAutoloader.php'); in the index.php, but now I get **include(MailMerge.php): failed to open stream: No such file or directory **.. The service is placed in protected/vendors/zend/zendservice/livedocx as said in the documentation.. any ideas? – Ilia Apr 04 '14 at 12:08
  • No, don't use this. Download composer. After that go to your protected folder (delete the vendor folder if you have only zend there) and type composer require "zendframework/zendservice-livedocx": "2.0.*@dev". This will create vendor folder and autoloader.php inside it. Proceed with my response above. – Nikola Apr 04 '14 at 12:17
  • Ok, sorry for the dumb questions but I'm really getting lost. Is this **https://getcomposer.org/download/** what I need and if yes how do I use that .phar file? – Ilia Apr 04 '14 at 12:24
  • Sry I'm on windows and it only works by typing composer. If you are linux and have a phar file the use it like this: php composer.phar ..... – Nikola Apr 04 '14 at 12:26
  • Ok, I'm dumb :D. I am also on windows and after the installation I use the command you provided and I get this: **Please provide a version constraint for the 2.0.*@dev requirement:** – Ilia Apr 04 '14 at 12:43
  • I have a typo the command is : composer require "zendframework/zendservice-livedocx":"2.0.*@dev" – Nikola Apr 04 '14 at 12:46
  • I have done everything you said, the vendor folder is generated, i changed the bootstrap index.php and still i get: **include(MailMerge.php): failed to open stream: No such file or directory** – Ilia Apr 04 '14 at 13:10
  • try this : new ZendService\LiveDocx\MailMerge – Nikola Apr 04 '14 at 13:46