PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 13, 2022

[FIXED] How to include a class from outside of cakephp folder

 February 13, 2022     cakephp, cakephp-3.0, cakephp-3.4     No comments   

Issue

Please see my current file structure

CakePHP
  - bin
  - config
  - src
  - vendor
  - webroot


RowPHP
  - push.php

I want to import/include Push class into my cakephp2 application which stands at push.php file outside of cakephp

Which I have tried

require_once( ROOT . DS . '..' . DS . 'RowPHP'. DS . 'push.php');
$pushOb = new Push(); 

it include successfully but when I try to create a object it through error

Fatal error: Class 'App\Controller\Push' not found

Question: How to import/include this class into my cakephp application ?


Solution

You need to ensure PHP can find the class in the correct namespace using new \Push() (note the backslash before the class name):-

require_once( ROOT . DS . '..' . DS . 'RowPHP'. DS . 'push.php');
$pushOb = new \Push();


Answered By - drmonkeyninja
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing