开发者

Create vendor class objects in components of cakephp

开发者 https://www.devze.com 2023-01-24 13:37 出处:网络
In cakephp, I want to import a vendor php file which contains different classes eg(class A class B, class C, each having __construct() method), in my component.I want to create objects of each class i

In cakephp, I want to import a vendor php file which contains different classes eg(class A class B, class C, each having __construct() method), in my component.I want to create objects of each class in the comp开发者_高级运维onent and call respective class function in my controller.

What is the correct process to implement it.


Try this

component:

  class LibraryComponent extends Object {
        public function classA($params) {
             App::import('Vendor', 'library', array('file' => 'classA.php'));
             $class = new classA($params);
             return $class;
        }
    }

controller:

$myClass = $this->Library->classA($params);
0

精彩评论

暂无评论...
验证码 换一张
取 消