1

I am setting up cron job in mac using crontab command.

I am using MAMP PRO as a local server environment for FRAPI API.

But I can not get Frapi_Database::getInstance() without using class or function in my simple PHP Script...

Actually function for getting database instance is as below :

 public function __construct()
 {
     $this->dbLink = Frapi_Database::getInstance();
 }

But I want to get database instance without using this method from Library,not from Action. How can I do this?

Ponting
  • 2,248
  • 8
  • 33
  • 61

2 Answers2

2

I also had same problem.Include this file into your Cron file:

/src/frapi/library/Frapi/AllFiles.php from Frapi API.

It has All necessary file like Libraries,database,adaptor files,etc.

Also If you getwarning like "PHP Notice: Undefined index HTTP_HOST" in internal.php file then replace

$_SERVER with getenv

You will get rid out of this.

India
  • 130
  • 7
0

You can do it directly by invoking the static method

$connection = Frapi_Database::getInstance();
DevZer0
  • 13,433
  • 7
  • 27
  • 51
  • Thank you for your reply..But i used same way as yours..So i got error like this in php_error log. PHP Fatal error: Class 'Frapi_Database' not found in this file..While running this file from crontab -l command. – Ponting Jul 09 '13 at 13:11
  • @DevZero : I can get database instance while running from Frapi..But outside Frapi (i.e. From command line or using crontab(Cron job)) i can not get database instance..Why? – Ponting Jul 10 '13 at 10:37
  • you need to include the "library/Frapi/Database.php" in your script – DevZer0 Jul 10 '13 at 10:42
  • @DevZero : I included Database.php.But I got error in Database.php that "Fatal error: Class 'Frapi_Exception' not found".Thank you for your reply. – Ponting Jul 10 '13 at 13:12
  • 1
    I read about Frapi and it said its a REST Framework. And the code looked like its been setup for WebAccess. i didn't see any initializer script. So you may have to include all the required files manually. For this error i believe you need `library/Frapi/Exception.php` – DevZer0 Jul 10 '13 at 13:17
  • @DevZero : Ok,I will try tomorrow and get back to you. – Ponting Jul 10 '13 at 16:34
  • @DevZero : I incuded all necessary files but I got error as : Undefined index: HTTP_HOST in /src/frapi/library/Frapi/Internal.php on line 310 ..Can you please give solution about this ? Thank you. – Ponting Jul 11 '13 at 06:26
  • @DevZero : I put my best efforts to find solution to resolve unidentified index : HTTP_HOST by searching and including files. But i can not find any solutions.Thank you for your answers..Can you please tell answer of this? It will help me a lot. – Ponting Jul 11 '13 at 12:07
  • well thats more of a warning not an error. did it prevent the script from running? – DevZer0 Jul 11 '13 at 12:09
  • @DevZero : yes it says `"PHP Notice: Undefined index: HTTP_HOST"`,Is it warning or error ? – Ponting Jul 11 '13 at 12:26
  • more of a Notice not even a warning – DevZer0 Jul 11 '13 at 12:31
  • @DevZero : Ok,Thank you..I reached at this error although i imported all the files under 'Cache/ and Cache/Adapter folder'. `PHP Fatal error: Uncaught Frapi_Cache_Adapter_Frapi_cache_adapter does not exist`.Your help will be appreciated. – Ponting Jul 11 '13 at 12:43
  • 1
    you also need `Cache/Adapter/Frapi` – DevZer0 Jul 11 '13 at 12:45
  • @DevZero : But there is no folder named as `Frapi` under `/src/frapi/library/Frapi/Cache/Adapter`. Thanks. – Ponting Jul 11 '13 at 12:49
  • @DevZero : There is no folder called `Cache/Adapter/Frapi`.Thank you. – Ponting Jul 11 '13 at 13:00
  • @DevZero Ok,Thanks for your help....If you have any other solutions for this question then please tell me... – Ponting Jul 11 '13 at 13:04