0

Him Can anyone tell me how can I access the library in ZEND framework and what is the proper naming convention for libraries in ZEND. I have the following struture


--application
--docs
--library
    --myLibrary.php (class name is also same)
--public

How can I access this library in my model?

Faizan Ali
  • 509
  • 12
  • 35

3 Answers3

4

The best way is to create your own library directory:

library
    My
        Library.php
    Zend

Add this to ypur index.php:

Zend_Loader_Autoloader::getInstance()->registerNamespace('My_');

And use this class:

$obj = new My_Library();
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
1

If your library is really a single class called myLibrary stored in library/myLibrary.php, then you should be able to add the following to your application/configs/applicatiom.ini file:

autoloadernamespaces[] = "myLibrary"

Then you should be able to instantiate a myLibrary object using:

$lib = new myLibrary();
David Weinraub
  • 14,144
  • 4
  • 42
  • 64
  • I did as u said. but I am getting the following error Failed opening 'Tt\Soap\Helper.php' for inclusion (include_path='E:\zend CE\Apache2\htdocs\store-app\application/library;E:\zend CE\Apache2\htdocs\store-app\library;.;E:\zend CE\ZendServer\share\ZendFramework\library') in E:\zend CE\ZendServer\share\ZendFramework\library\Zend\Loader.php on line 146 – Faizan Ali May 18 '12 at 05:15
  • Does the file `Tt/Soap/Helper.php` reside on your `include_path`? – David Weinraub May 18 '12 at 05:26
  • my library name is Tt_Soap_Helper. and yes I assume that it resides on include path. coz the folder path in error is right. – Faizan Ali May 18 '12 at 05:28
  • please help me out.. I am stuck here – Faizan Ali May 18 '12 at 05:46
  • @FaizanAli: Seems we are misunderstanding each other re: the terms 'library name' and 'class name'. `Tt_Soap_Helper` is a 'class name'. It resides in the `Tt` pseudo-namespace, so it is pretty common to refer to `Tt` as a 'library'. If the `Tt` folder resides in your `library` folder, then you should only need to add another `autoloadernamespaces` entry to your `application/configs/application.ini` file: `autoloadernamspaces[] = "Tt_"` – David Weinraub May 18 '12 at 06:34
  • lets just say .. that I have a class with a name Tt_Soap_Helper. it contains custom soap helper function I have written. Where should I place this file according to ZEND standards ? and how do I autoload this file so that I do not have to include it to use it – Faizan Ali May 18 '12 at 09:56
  • 1
    @FaizanAli: See my answer above. Place the file containing the class `Tt_Soap_Helper` in `library/Tt/Soap/Helper.php`. Then in `application/configs/application.ini`, add a line: `autoloadernamespaces[] = "Tt_"` (my previous comment had a typo). Then any call like `$helper = new Tt_Soap_Helper();` will invoke the autoloader. – David Weinraub May 18 '12 at 10:13
0

Well if your library folder is on the include path then you can use myLibrary directly.

Songo
  • 5,618
  • 8
  • 58
  • 96
  • it is on the include path. but I am constantly getting that anoying error that library is not present there – Faizan Ali May 18 '12 at 05:26