Welcome Guest, Not a member yet? Register   Sign In
Where to put data logic not related with database?
#2

Create new layer in app/Services. Write some functional inside


PHP Code:
// app/Services/TextWriter.php

<?php

// here some function for job with repository, entity, helper, etc
class TextWriter {
    public function modify(string $text): string {
        return str_replace('...''***'$text);
    }
}

// app/Controllers/TextController.php

<?php

class TextController extends BaseController {
    public function index(int $id) {
        $textWriter = new TextWriter();
        $model = new BookModel();
        $book $model->find($id);
        $book['text'] = $textWriter->modify($book['text']);

        return view(..., ['book' => $book]);
    }

Simple CI 4 project for beginners codeigniter-expenses
Reply


Messages In This Thread
RE: Where to put data logic not related with database? - by ozornick - 07-12-2023, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB