Use a PHP file to Symfony -


i have php file connected elasticsearch, indexing documents.

my elasticindex.php file:

    **class elasticindex{  function elasticfun(){  require 'vendor/autoload.php';     $client = new elasticsearch\client();      $feed = 'http://blaasd.zasdp.tv/xml';     $xml = simplexml_load_file($feed);     foreach ($xml-> .......     ......}** 

now problem working on symfony framework, in beginning of php file have address namespace, like:

**namespace mybundle\controller** 

that why unable use following 2 lines in controller class:

require 'vendor/autoload.php';     $client = new elasticsearch\client(); 

so have created new php file (elasticindex.php)and writen code elasticsearch indexing. how can call function elasticfun() elasticindex class controller class. not using namespace in elasticindex class, not address anywhere in symfony project.
how can call elasticfun() function not addressed anywhere controller class?

i have try use global namespace ---

**use mybundle\videoproviderclient\elasticindex _val; class externalclientcontrolcontroller extends controller {     public function externalclientcontrolaction() {                 $_val = new \elasticindex();         return new response($_val);     }** 

it gives error -- attempted load class "elasticindex" global namespace.did forget "use" statement?

can kindly me this. lot in advanced ...

you need import namespace elasticsearch object controller class.

typically done use statement near top of file (under namespace declaration class), i.e.:

namespace mybundle\controller  use elasticsearch;  class index {      public function indexaction() {         $client = new elasticsearch\client();     } } 

for arbitrary php files can either refactor them symfony / composer's autoloading structure or use classloader functionality manually load classes best suited specific requirements:

https://github.com/symfony/classloader


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -