I always do the same things, how do I make it a one time ? (function ? library ? class ? helper ?) |
[eluser]Dagobert Renouf[/eluser]
Hello everyone, I'm still building my modest CMS and as I was coding a second part to my admin zone, I saw a huge pattern telling me "you could do that in 3sec if you weren't that stupid". Since my oop knowledge is just enough to "get it" and that I'm fairly new to CodeIgniter let me ask you this EVERYONE CAN DISCUSS question : " What is the best approach to transform a long repetitive action into one that would change with parameters ? ". (I know it's the definition of functions but this is more complex). Here's my example (don't care about the lenght, this is just for you to see the pattern) : Code: function add_entry() AND Code: function add_() So I'm asking you guys, how do I manage to hanlde this pattern, because I'm gonna need to create dozens of theses, that's really not a great approach IMO.
[eluser]Tom Glover[/eluser]
Use Snippets of the most common code in your IDE or Editor.
[eluser]Dagobert Renouf[/eluser]
ahah wackywebs, that's really not my point here, but thanks that's a solutions ;-). I'm talking about creating a library or a class or a helper or an extension to one of theses etc... I'm asking which solution I need to choose and how to create it!
[eluser]Référencement Google[/eluser]
Without looking really at your code, I just advice that you go with some libraries. Personally, I try to keep my controllers for what they are intended to: drive the application. All procedural code I put in libraries.
[eluser]Dagobert Renouf[/eluser]
Thank you too pixel ;-). While browsing, I found out codeextinguisher and rabbitforms, that would in this case realy help me out. Any thoughts about theses and how they are adapted to my problem ?
[eluser]xwero[/eluser]
I would autoload the form helper. that and url are the two helper is load all on all the sites. I put the validation for a model in a model with the name [modelname]validation and i automagically load it with a customized front controller. It doesn't make the code less but it keeps the code out of the controller. Why don't you do the two validations together if the file upload is required to add the data Code: // common fields validation rules Code: $insert_id = $this->blog_model->insert_entry($values);
[eluser]Dagobert Renouf[/eluser]
Hi xwero and thank you. I don't really see what your point is, I'm asking how I could create a small library that would allow me to create simple forms (add edit delete) in minutes instead of doing all this. I'm also asking if rabbitform/codex fit my needs or if they are too big for this. About that : Code: $admin_action_data = array('action' => 'add', 'identifiers' => $this->db->insert_id()); $this->db->insert_id() is not to insert data, this gives me the id of the row I just created in the database. I use it to display informations about the post on the next page.
[eluser]xwero[/eluser]
Yes i know the insert_id in not to insert the data :coolsmile: but you better put that method in the insert_entry method of the model. Lets say you want to add a post but your database server goes down for some reason then you can check if the insert really took place or not. Or if you want to use the method in some other controller method and you need the insert id again you need to add the insert_id method again. Data related methods should be confined to the models. The controller as you wrote it is too smart because it knows the data comes from a database.
[eluser]Dagobert Renouf[/eluser]
So you say that the insert_entry should return the "$this->db->insert_id()" ?
|
Welcome Guest, Not a member yet? Register Sign In |