Author Topic: how to use different library in ZF ?  (Read 702 times)

0 Members and 1 Guest are viewing this topic.

Offline sasoriTopic starter

  • Enthusiast
  • Posts: 269
    • View Profile
how to use different library in ZF ?
« on: August 21, 2010, 10:19:53 PM »
I added a new folder inside the library folder and named it as "Form" ( so now I have two folders, the Form & Zend )
inside the "Form" folder, I added a file named "Elements.php"
inside the "Elements.php" I have named the class as
class Elements{}
now the question is, How will I use that Elements class to another class without having to use the require() function just like the Zend libraries ?  :confused:

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: how to use different library in ZF ?
« Reply #1 on: August 21, 2010, 10:28:51 PM »
You just need to register your namespace with the autoloader.


require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->registerNamespace('Form_');

Offline sasoriTopic starter

  • Enthusiast
  • Posts: 269
    • View Profile
Re: how to use different library in ZF ?
« Reply #2 on: August 21, 2010, 10:33:29 PM »
nothing happened, there's still an error that the class cannot be found.. am I doing the right thing?
1) the file name is Elements.php
2) the class name is Elements.php
3) folder name is "Form"
4) registerednamespace("Form_")
5) called the file to another class as,  new Form_Elements();

is the correct or ?

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: how to use different library in ZF ?
« Reply #3 on: August 21, 2010, 10:36:17 PM »
Quote
2) the class name is Elements.php

That isn't even valid php. The class would need to be named 'Form_Elements'.

Offline sasoriTopic starter

  • Enthusiast
  • Posts: 269
    • View Profile
Re: how to use different library in ZF ?
« Reply #4 on: August 21, 2010, 10:38:11 PM »
sorry, i mistyped .php, on my reply


how about when using it to another class ?
is it "$var = new Form_Elements()" or "$var = new Form_Element" ?

Offline sasoriTopic starter

  • Enthusiast
  • Posts: 269
    • View Profile
Re: how to use different library in ZF ?
« Reply #5 on: August 21, 2010, 10:39:02 PM »
ok nevermind..it worked...thanks for the Help.. ++rep for you :)