3

I have a CakePHP project with this structure:

myrootapp
|__ app
   |__webroot
      |__soap.php

I'm calling my webservice in this soap.php, but I am calling some cakephp controller inside of my webservices functions like this link.

But the App::import causes an error in my application because the App::import is not imported into soap.php.

How I can import and use the CakePHP function in my soap.php page inside the webroot folder? I want to use App::cakephpFunctions to import the controllers.

** UPDATE**

I'm calling App:import inside the soap.php in webroot. I wanna solve this and call my controllers in this file.

PHP Fatal error:  Class 'App' not found in 

Thanks.

Community
  • 1
  • 1
ErasmoOliveira
  • 1,416
  • 2
  • 20
  • 40
  • Please check this link :- http://stackoverflow.com/questions/14264188/cakephp-include-class-from-a-directory-outside-the-app-directory – Alive to die - Anant Mar 25 '15 at 14:49
  • @anantkumarsingh Its is not possible to use APP::import or APP:uses, its create a error, But I wanna import this functions inside of my file. but how I import App or create something to get permissions to use this function inside of webroot folder – ErasmoOliveira Mar 25 '15 at 14:56
  • Try to include your controller file in your soap.php and create object of that controller class and use it. If this is not possible then include your controller file in your soap.php and make that function static which you want to use. – Alive to die - Anant Mar 26 '15 at 05:42
  • Just try to include webroot's index file in your soap.php file and then use App::import() – Vineet Mar 26 '15 at 11:38

3 Answers3

4

In order to use stuff from the framework, you need to load/initialize it first. You can do that by including the CakePHP bootstrap file into your soap.php file:

require_once('/path/to/your/cakephp/lib/Cake/bootstrap.php');

That will initialize the framework, including the App class.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
  • I tried, but I receive this error: PHP Fatal error: require(): Failed opening required 'C:\xampp\htdocs\epedidos\libDSCakeDSbasics.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\epedidos\lib\Cake\bootstrap.php on line 138 – ErasmoOliveira Mar 30 '15 at 13:05
  • @ErasmoOliveira Ah yes, looks like you're missing some constant definitions. See https://github.com/cakephp/cakephp/blob/2.6/index.php#L26-L30 for some core constants that the framework uses. DS is the Cake shortcut for the PHP `DIRECTORY_SEPARATOR` constant. – Oldskool Mar 30 '15 at 20:05
  • 1
    after add index.php work. its done, thank you @Oldskool – ErasmoOliveira Mar 30 '15 at 20:50
-1

Try this

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://localhost/app/controller/functionName"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch);  
curl_close($ch);

CakePHP has quite good tools for it: http://book.cakephp.org/2.0/en/development/rest.html

Amit Maan
  • 85
  • 9
-1
App::import('Model', 'YourModelName');
$result = new YourModelName();
$abc = $model->find('all');
Vinod Saini
  • 85
  • 12