I am working in zend and in admin panel I have to export my data I am using PHPExcel for doing this here is the folder structure
Admin
src
admin
Controller
view
Vendor
PhpExecl
standard
src
standard
static option
I am using $objPHPExcel = new \PHPExcel(); in static option
I am calling export function from my controller which is in the static option page but it is showing me 500 error
can you help
or if some body has a even better option then please post it
I just worked with that lib the other day, make sure you include the path to the Phpexcel library classes in your php include paths:
set_include_path(get_include_path().PATH_SEPARATOR.APPLICATION_PATH.'/your-path/phpexcel/Classes/');
The problem is related to autoload PHPExcel classes.
For sure a better option to avoid to have problems with autoload PHPExcel classes, and avoid to manual adding the classes in the include path, is to use MvlabsPHPExcel that gives an easy integration of PHPOffice/PHPExcel library into zend framework 2.
Related
I'm facing trouble when using PHPWord with CodeIgniter in loadTemplate always return error "Template Not Found".
I'm using phpword in third party and create Word.php class in library to call it.
My CodeIgniter not a pure one. It already injected like some homemade cms from previous programmer.
My Question is how to I know where is the path of loadTemplate?
Any info needed you can ask me I will provide for you
Thanks,
Hendra
I'm not sure if I understood your scenario, but in any case there is no magic in how the path of loadTemplate works - it works exactly the same as you would access any file with php, i.e. either you place your template file under the phpunit library and use a relative path or you place your file somewhere else and use a full path (or some alias if you have some defined in your server (apache/nginx/..) configuration).
I have a make a file in the magento root. like below
Foldername/pay.php
This files call api and work with some lib. when i call it through direct in the browser url.
I want to call this within magento function.
pay.php have a class and I add this file within a magento module file and make a object but it shows the error of object reference.
What should i do? Please suggest me.
Thanks in advance to all magento dev
put your library at [magento]/lib folder
for example your library is PhpExcel so you have to put it in [magento]/lib/PhpExcel
and include your library in magento file before call.
$includePath = Mage::getBaseDir(). "/lib/PhpExcel/Classes";
set_include_path(get_include_path() . PS . $includePath);
so you have create object of PhpExcel library to access it
$objPHPExcel = new PHPExcel();
for your reference download PhpExcel Export and check directory structure as well way to access external library in magento.
it create a object in [magento]\app\code\local\Conlabz\Mreport\controllers\Adminhtml\ExportController.php
hope this help you
I'm using zend framework2 skeleton, and I'm trying to add my own classes behind vendor folder. The problem is: I don't know how to prepare the classes to be loaded on demand (autoloaded) only when I'll instantiate one of them from any module.
I tried with the solution explained at: How to load a custom library in Zend Framework 2? , but I'm getting the same error:
Fatal error: Class 'myNamespace\myClass' not found in path\IndexController.php on line x
My question is: Where and how should I insert my own classes to be later used from my modules?
Firstly, if they are your own classes and directly related to the modules (i.e not some custom library you have written) then you are better off having them in the actual module, not in the vendor folder.
However, if you are trying to include your own library that you have written I'd suggest you consider storing this elsewhere and adding it as a dependancy via composer.
I don't recommend this but you should be able to get the autoloading working by using the psr0 autoloader built in to composer (assuming your classes follow psr0). Example composer.json config:
{
[...]
"autoload": {
"psr-0": {
"MyNameSpace": "path/to/root/src/directory"
}
}
[...]
}
I know its a bit old but i was facing the same issue so what i did was:
inside vendor folder i created a new folder and gave it the name of Custom. Inside that folder i added my class file (MyClass.php).
inside MyClass.php i added this line (namespace Zend\Custom;).
And inside my Controller at the top
use Zend\Custom\MyClass;
and within a method of that controller
$someVar = new MyClass();
$someVar->someClassMethod();
I hope this helps.
I want to parse a PDF document in my project, I'm using Yii framework and I'm able to load ZendFramework 1.12, actually I'm using Zend_Lucene and Zend_Mail successfully, but ZendPdf fails to parse the PDF, so I wanted to try with ZF2 (ZendFramework 2), but I'm not able to make it work... I just downloaded the ZF2 library and added the following to my base Controller:
public function __construct($id,$module=null){
Yii::import('application.vendors.ZendFramework.library.*');
Yii::setPathOfAlias('Zend',Yii::getPathOfAlias('application.vendors.ZendFramework.library.Zend'));
parent::__construct($id,$module);
}
So every time I use a Controller this code is executed. Then in the controller I have:
use ZendPdf\PdfDocument;
use Zend\Mail;
class AjaxController extends Controller{...
...
public function actionTestPdf(){
$filepath = realpath('./path/').'/pdftest2.pdf';
$pdf = PdfDocument::load($filepath);
}
When I run the controller: /ajax/TestPdf
I get: Fatal error: Class 'ZendPdf\PdfDocument' not found
What am I doing wrong?
I'd suggest you to install your ZF2 stuff with composer and include the autoloader from composer to get PSR compatible autoloading.
Alternative 1)
You may also try pointing an alias ZendPdf\PdfDocument to the class file location.
Alternative 2)
import the needed classes or directories in your application config.
In this particular case I would recommend NOT using ZendPdf from ZF2, because it is functionally equivalent to Zend_Pdf from ZF1 and so all you're going to do is add unnecessary complexity with classloading, etc, but not solve your underlying problem, as the document will still most likely NOT load using ZendPdf from ZF2.
You should investigate the underlying reason why the document is failing to load in ZF1.
I have few PHP classes and files that I want to include in Joomla so that I can call those classes. I tried doing require_once config.php to include a PHP file which also includes all the classes that I would want to use in Joomla.
But each time I execute the page I receive the error below:
Fatal error: Class 'SomeClassName' not found
is there any other way to include external PHP classes or files in Joomla?
Thanks in advance!
Please use Joomla autoloader. Is better.
<?php
// Register an adhoc class.
JLoader::register('AdhocClass', '/the/path/adhoc.php');
// Register a custom class to override as core class.
// This must be done before the core class is loaded.
JLoader::register('JDatabase', '/custom/path/database_driver.php', true);
Edit:
Load classes with autoload instead of require/include have a better performance, because PHP will only read (require access to the disk) and compile (require memory and CPU usage) if you really use your class.
To do the same with require/include you have to be sure to only use if will really use the class.
Source:
http://developer.joomla.org/manual/ch01s04.html
require_once should work just fine within Joomla. Make sure the class you want to use is really loaded within your file, and the file is properly referenced in the require_once. Something is going wrong there and it has nothing to do with Joomla itself :-)