0

I am trying to use a custom class in cakephp. Initially I had created a vendor class which works fine but I can't use other cakephp components.

To use built in components like $this->Text, I can create a custom component but the constructor requires a argument which is a json object returned from an API and I need to keep initializing in a loop

//The constructor for the class
function __construct($objValue) {
$this->messageId = $objValue['id'];

Is using a component suitable for this purpose?

1 Answer 1

1

you don't need to create a component here if you don't need it in the controller scope. also you don't need to make it a vendor class (which is third party stuff).

cake offers you a way out: Libs in APP/Lib You can use them anywhere anytime.

App::uses('MyClassName', 'Lib');
$MyClass = new MyClassName();

You might even want to create a package in Lib itself - e.g. "Lib/Utility":

App::uses('MyClassName', 'Utility');

without knowing any more about what exactly this custom class does, it is difficult to be any more specific here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.