Welcome Guest, Not a member yet? Register   Sign In
admin controller
#1

[eluser]owidiuszek[/eluser]
Hello guys (and ladies?? Big Grin )


When I look on my backend controllers almost every controller shares same idea.

We have some content item (user, post, category, player, team, event, image whatever).
And on each of this content items I'm making same routine like add/edit , delete, validate plus some specific ones.

I know that I can make my_model for most common stuff done on model side (I'm using doctrine on most of my projects so its a little different) but I'm not saying about model - I would like to talk about controller.

for each add I'm add/edit I'm making same things:
- checking post data (if is sent, from which form, some other checks like permissions)
- validating
- deciding whether add or update
- perform those actions
- make some specific stuff related to specific content type(like creating directory)
- notifying user
- redirecting back


and this pattern is common for most of my admin controllers.

And now I have question :
What kind of best practice would You suggest. Should I extract most common actions to my admin_controller or try to make controller as light as possible and throw everything to model? Please remember that I'm talking about post data checks, validation, directory creating etc not about exact CRUD, sql stuff
#2

[eluser]InsiteFX[/eluser]
CodeIgniter Base Classes: Keeping it DRY by Phil Sturgeon

InsiteFX
#3

[eluser]owidiuszek[/eluser]
Yes I have it this way


edit:
Sorry I was not precise.

I have My Controller and Admin Controller, Public Controller


what I was asking was: what would You exctract from all controllers to Admin Controller. Do You ahve Your own best practises? What I saw across the internet - people were using admin controller or public controller to for example make permissions or login for all controllers or remap some routes.
I have never seen that somebody extracted for example validation, form processing to admin controller.

example:
Code:
public function foo($param1)
    {
//if posted
            {
                if ($this->_submit_validation() === FALSE ){
                    //display form            
                }
                else
                {

                    $form_data = array(some data);

                    if ( ! $this->_source_data_exists($param1))
                    {
                        //add
                    }                    
                    else
                    {
                        //update
                    }

                    //notify and do something else
                }
            }
        else
            {
                //display form
            }
    }

and almost every add/edit in my controllers is matching this pattern. Is it worth to try extract it to admin controller?

With usage of model functions my controllers are pretty small. I would like to make it more "DRY" by not repeating same pattern at each.

When I look at it I know that i can move displaying forms or some other smaller functions to Admin Controller but the rest like validation is very specific for each controller.

Do You have some best practices? Or is not worth?
#4

[eluser]InsiteFX[/eluser]
You could put this stuff into a library and then load the library
to handle form stuff.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB