Welcome Guest, Not a member yet? Register   Sign In
Custom Classes : general questions
#1

Hello,

I'm quite a newbie on CI4 and I've got general questions.

Few years ago, I've created a php class that helps me to create a small CMS and build my contents. It creates for me the html form to manipulate my tables easily (add and remove tables, add and remove lines, add fields, resort, hide elements)... a bit like phpmyadmin but much simpler, specific to my app (I can chose how I want to edit my tables), and visually more ergonomic. Actually my class did the model-view-controller for me.

Now I want to go on with CodeIgniter and adapt my php class on CI4 to get a better "structure". 

1 - What do you think about creating a class that I can use in many Models, Views and Controllers ? 
2 - Where should I put this class "for a good practice" and call it if I would like to use it with several controllers, models and views ? 
3 - And last question : Does something already exists like that ? ... A plugin in CodeIgniter4 for adding quickly content in databases ?

Thank you a lot for your help !
Reply
#2

(06-23-2020, 05:38 AM)kilden Wrote: Hello,

1 - What do you think about creating a class that I can use in many Models, Views and Controllers ? 
2 - Where should I put this class "for a good practice" and call it if I would like to use it with several controllers, models and views ? 
3 - And last question : Does something already exists like that ? ... A plugin in CodeIgniter4 for adding quickly content in databases ?

Thank you a lot for your help !

The class already exists and it bears the name of the framework - CodeIgniter.
Reply
#3

(This post was last modified: 06-23-2020, 07:53 AM by kilden.)

Aha. Well, thank you for your "constructive reply" that does't help me a lot, but... please... I kindly asked for best practices as it is written on the top of this forum... I know Codeigniter allows a lot of things, but so far as I know, when you install it, you don't have an integrated cms, and even less in Ajax... You need to build everything as you like.

So maybe my question is stupid, or misconceived, but I was just wondering if it is a good practice to create a class to generate specifics html elements and repetitive kind of queries that would be helpful for building my cms. Or, the good practice is to create everything in controllers for adding specifics html and queries ?
Reply
#4

You can add the class to CodeIgniter's Libraries folder and then use the autoload features to
load it.

But what your talking about I would just re-write it in CodeIgniter 4 and use Controller's model's etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 06-23-2020, 12:10 PM by jreklund.)

1 - What do you think about creating a class that I can use in many Models, Views and Controllers ?
- If it's an all in one application, that allows you to modify all the tables in the database, I would make it a "Code Module" that you can drop in place in any application you make.
https://codeigniter.com/user_guide/general/modules.html

2 - Where should I put this class "for a good practice" and call it if I would like to use it with several controllers, models and views ?
- If it's a normal application, not a database manager you generally create one controller, one module and one view for everything.
-- Adding a page
-- Adding news
...

A single controller, model or view don't generally handle everything. Sure you can do it, but that's not normally something you do.

3 - And last question : Does something already exists like that ? ... A plugin in CodeIgniter4 for adding quickly content in databases ?
- There are a beta of Grocery CRUD, if that's what you are after: https://www.grocerycrud.com/
Reply
#6

Many thanks for all your very interesting answers. I will have a close look !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB