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

Tuesday, February 22, 2022

[FIXED] Import a library with CakePHP

 February 22, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

I am using CakePHP (v3.0), and my Controller code is as below:

namespace App\Controller;

class ArticlesController extends AppController{

    public function index(){
        $context = new BLTI("secret", true, false);
    }
}

I want to create a BLTI object. I have a folder whose name is ims that contains the following PHP files:

  • blti.php (contains two class, one of them is "BLTI")
  • blti_util.php
  • OAuth.php

I have placed this ims folder in vendor directory. My problem is that i don't know how I must import this ims folder in my Controller to use it.


Solution

App::import() has been removed in CakePHP 3.0, so simply require() the files and use the use statement to load the classes into your namespace.

Normally you would just add them to your autoloader, but obviously these files and classes are pretty old and don't care about best practice (one class per file) or follow any convention for automated file loading.

You could change the files naming of that lib as well so that they can be used with the autoloader. Should be easy to do as well.



Answered By - floriank
  • 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