Bibudha Sahoo
Bibudha Sahoo

Reputation: 31

can we use zend library in our own php application

is it compulsory to use zend framework structure for using zend library or we can use zend library in our own php application...

Upvotes: 2

Views: 129

Answers (1)

David Weinraub
David Weinraub

Reputation: 14184

Three steps to using the ZF (assuming ZF1) library in your own app without the entire ZF MVC stack.

  1. Set the include path

    Make sure that the Zend library folder is on your php include_path.

  2. Load your class

    You could just include each class file before you use it:

    require_once 'Zend/Validate/EmailAddress.php';
    $validator = new Zend_Validate_EmailAddress();
    

    But it's a pain to do it that way. Typically, it's better to using the autoloader. The easiest way is something like (early in your bootstrap process, perhaps in a common.php file, YMMV):

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

    Once this is done, you can instantiate/reference on-demand:

    $validator = new Zend_Validate_EmailAddress();
    
  3. Instantiate/Reference

    $validator = new Zend_Validate_EmailAddress();
    echo $validator->isValid('[email protected]') ? "Cool" : "Fail";
    

Upvotes: 2

Related Questions