2017-03-09 116 views
0

我尝试在codeigniter框架中安装phppresentation库。但在codeigniter中无法使用名称空间。那么如何整合?在codeigniter框架中安装phppresentation

+0

你究竟做了什么仍然不清楚..:/ –

+0

实际上在他们使用'use'和'namespace'的phppresentation库中。因此,这个库在codeigniter框架中不起作用。所以如何解决这个问题。 –

+0

请编辑你的问题描述你遵循的步骤来安装库... –

回答

0

这可能不是“最佳实践”示例,但我在PHPPresentation Packagist page上获得了“入门”示例以在CI 3.1.3中工作。

我按照CI手册中的描述使用默认方式来使用composer。

应用程序和系统目录从根目录上升一级。

composer.json文件位于应用程序目录中。

从packagist页面下面粘贴到composer.json并运行composer update,将其保存到application/vendor/phpoffice中。

{ 
    "require": { 
     "phpoffice/phppresentation": "dev-master" 
    } 
} 

在应用程序/库创建Ppt_stuff.php。剪切粘贴入门示例到文件中。必须添加类名和函数make_ppt。还用realpath('.')修复了setPath和Save函数的路径名。

<?php defined('BASEPATH') OR exit('No direct script access allowed'); 

use PhpOffice\PhpPresentation\PhpPresentation; 
use PhpOffice\PhpPresentation\IOFactory; 
use PhpOffice\PhpPresentation\Style\Color; 
use PhpOffice\PhpPresentation\Style\Alignment; 

class Ppt_stuff { 

    public function make_ppt() { 

    $objPHPPowerPoint = new PhpPresentation(); 

// Create slide 
    $currentSlide = $objPHPPowerPoint->getActiveSlide(); 

// Create a shape (drawing) 
    $shape = $currentSlide->createDrawingShape(); 
    $shape->setName('PHPPresentation logo') 
     ->setDescription('PHPPresentation logo') 
     ->setPath(realpath('.') . '/../application/vendor/phpoffice/phppresentation/samples/resources/phppowerpoint_logo.gif') 
     ->setHeight(36) 
     ->setOffsetX(10) 
     ->setOffsetY(10); 
    $shape->getShadow()->setVisible(true) 
     ->setDirection(45) 
     ->setDistance(10); 

// Create a shape (text) 
    $shape = $currentSlide->createRichTextShape() 
     ->setHeight(300) 
     ->setWidth(600) 
     ->setOffsetX(170) 
     ->setOffsetY(180); 
    $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); 
    $textRun = $shape->createTextRun('Thank you for using PHPPresentation!'); 
    $textRun->getFont()->setBold(true) 
     ->setSize(60) 
     ->setColor(new Color('FFE06B20')); 

    $oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007'); 
    $oWriterPPTX->save(realpath('.') . "/downloads/sample.pptx"); 
    $oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation'); 
    $oWriterODP->save(realpath('.') . "/downloads/sample.odp"); 

    } 

} 

在根目录created/downloads目录中。

将此添加到主控制器。

public function use_presentation() { 

    // load library 
    $this->load->library('Ppt_stuff'); 
    // call make_ppt 
    $this->ppt_stuff->make_ppt(); 
    return; 

} 

走到http://localhost/home/use_presentation,它创造了/下载sample.pptx和sample.odp。

当我打开它们时,Powerpoint 2010抱怨并提出修复它们。