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

I am retrieving data from files (with library), then parsing it (with ?) and then saving parsed data into database (with model). I want this three steps separated. Where should I put parser?

Models in CodeIgniter are binded with database tables ($table variable is mandatory) and libraries should be used for common things, not for a specific jobs. I was thinking models should be used for working with any data, not only for database related things. But binding models with tables confusing me. Thank you for your suggestions.

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

PHP Code:
// app/Services/TextWriter.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


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

Theme © iAndrew 2016 - Forum software by © MyBB