CodeIgniter Forums
add on system codeigniter 4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: add on system codeigniter 4 (/showthread.php?tid=82535)



add on system codeigniter 4 - devo - 07-20-2022

how can i make add-on / plugins system in codeigniter 4 can someone please give me a reference?


RE: add on system codeigniter 4 - captain-sensible - 07-20-2022

well lets take your terminology of plugin , something i might have heard concerning WordPress to mean "how can I extend functionality"?

So lets say you want to include the functionality of a spam checker ; it will check input from a form to see if the user of the form is a spammer. I can only give you mu approach. So the way i went about it is to write a php class; but it won't be a controller.

So to make it easy to be found I create a directory called "Andy" inside the codeigniter4 "app" directory.

Inside the class at the start i write :
Code:
<?php namespace App\Andy;




class CheckSpam
{


inside my class "CheckSpam" keeping it simple i declare an array of usual suspect spam key words eg containing 'free consultation','Toenail Clippers',


to use my class its just a case of getting an instance of it and passing data to one of its methods . basically text from a submitted form will be run through , using each key word in my array. Sounds slow and tedious but works a treat. Anybody that wants to test it live let me know

So its just like a plugin for say wordpress , but i have gone about it using a class.


With a class you can just about do anything ; also a class have have several methods which each do something different