Dan
Dan

Reputation: 1413

Where to put common logic in cakephp app

This is something I have struggled with for a while to get my head around

I have a shell which at the moment grabs data from a 3rd party, processes it and saves processed data into my db. The processing can save to related tables as well.

I also want to have some way of submitting data via chrome extension to be processed in the same way. The data is going to be in the same format in both scenarios so I was hoping to move the logic I have in my shell into something that both a shell and controller can use.

Part of my processing involves loading any currently saved data in some situations too - and I found that I can't use loadModel unless I am in a controller?

So where should this logic go, and how do I make sure that solution has access to all the part of the framework I need still?

Upvotes: 0

Views: 66

Answers (1)

Ved
Ved

Reputation: 746

You can create an Utility folder under src containing php files.

Here you can define your namespace of class and can instantiate easily.

You can use statements also.

--src
 |--Utility
    |--Example.php 

<?php

    namespace App\Utility;

    class Example
    {

     function __construct() {
        //constructor
     }

    function demo() { 
       //function for specific task
   }

}

Upvotes: 1

Related Questions