![]() |
Using something like a helper in model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Using something like a helper in model (/showthread.php?tid=80381) |
Using something like a helper in model - sprhld - 10-26-2021 Hi there! How to start... ![]() PHP Code: public function crtSlug(string $name, $test = FALSE) My first Idea was to create a helper, but as you see, the method uses the model and the helper has no access to the "builder()". So my question is: how to create global method which are only works local, in the specific model? Thanks! RE: Using something like a helper in model - includebeer - 10-26-2021 You can create a base model class that contains crtSlug() and make your three models extend this base class. RE: Using something like a helper in model - sprhld - 10-26-2021 Oh, that was easy :-) I thought, it would be a problem to use the builder. For all other noobs like me, here is what I did: First, I extend the Model: PHP Code: <?php PHP Code: <?php Thank you! RE: Using something like a helper in model - includebeer - 10-26-2021 Cool, glad it solved your problem! ![]() RE: Using something like a helper in model - sprhld - 11-01-2021 And I found more ;-) My method to create a slug is always used on INSERT and UPDATE. In that case, you can make use of events: https://codeigniter.com/user_guide/models/model.html#model-events It's on my todo-list for my program... |