onalbi
onalbi

Reputation: 2759

Best way to load external library in symfony 1.4?

I've searched a lot how to load/include a simple class in symfony 1.4 and i found nothing. I have this situation.

Under:

./apps/APP_NAME/
    modules/MOD_NAME/lib

I have a class:

class MyClass {
   function get_data(){
      retrun "data";
   }
}

Update: I want to load on demand, not to autoload with the convention of symfony 1.4 naming the file MyClass.class.php

Upvotes: 3

Views: 1261

Answers (2)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

This file allows you to define extra classes that can be autoloaded when Symfony loads. and Symfony allows you to place php code inside a .yml file

##apps/appName/config/autoload.yml
autoload:
  makeupaname:
    name: Make up a name
    path: <?php echo $mydynamicvar; ?>/someFolder/
    recursive: on
   
  makeupasecondname:
    name: Make up a second name
    path: <?php echo $mydynamicvar; ?>someOtherFolder/
    recursive: on

as well as go thorough this extra links autoloading namespaces in symfony 1.4 and How to create/use custom classes and helper in symfony 1.4?

Edit 01

If you want to place externel library you have to place that in lib/vendor folder. You cant create that inside app folder.

As well as if you just add new library to that and site will not load your library. So that only you have to use the autoload file to do that

This article help you out. Loading external libraries for symfony 2

Upvotes: 0

onalbi
onalbi

Reputation: 2759

Is not the best but a first version that work under module ENV is:

    function load_module_lib($module, $name_file) {
       require_once (sfContext::getInstance()->getModuleDirectory() . '/../' . $module . '/lib/' . $name_file . '.class.php');
    }

Upvotes: 1

Related Questions