Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 849625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:07:59+00:00 2026-05-15T07:07:59+00:00

This has bothered me for quite a while, but now it is necessity that

  • 0

This has bothered me for quite a while, but now it is necessity that I find the answer.

We are working on quite a large project using CodeIgniter plus Doctrine.

Our application has a front end and also an admin area for the company to check/change/delete data.

When we designed the front end, we simply consumed most of the Doctrine code right in the controller:

//In semi-pseudocode
function register()
{
  $data = get_post_data();

  if (count($data) && isValid($data))
  {
    $U = new User();
    $U->fromArray($data);
    $U->save();

    $C = new Customer();
    $C->fromArray($data);
    $C->user_id = $U->id;
    $C->save();

    redirect_to_next_step();
  }
}

Obviously when we went to do the admin views code duplication began and considering we were in a “get it DONE” mode so it now stinks with code bloat.

I have moved a lot of functionality (business logic) into the model using model methods, but the basic CRUD does not fit there.

I was going to attempt to place the CRUD into static methods, i.e. Customer::save($array) [would perform both insert and update depending on if prikey is present in array], Customer::delete($id), Customer::getObj($id = false) [if false, get all data]. This is going to become painful though for 32 model objects (and growing).

Also, at times models need to interact (as the interaction above between user data and customer data), which can’t be done in a static method without breaking encapsulation.

I envision adding another layer to this (exposing web services), so knowing there are going to be 3 “controllers” at some point I need to encapsulate this CRUD somewhere (obviously), but are static methods the way to go, or is there another road?

Your input is much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:08:00+00:00Added an answer on May 15, 2026 at 7:08 am

    Why not use a facade?

    class RegistrationManager {
     public function register( $postData, $callBack ){
          $data = get_post_data();
          if (count($data) && isValid($data)){
            $U = new User();
            $U->fromArray($data);
            $U->save();
            $C = new Customer();
            $C->fromArray($data);
            $C->user_id = $U->id;
            $C->save();
            $callBack(); //I like this but you need PHP5.3
          }
         }
     }
    

    In your app controllers:

    $r = new RegistrationManager;
    $r->register( get_post_data(), function(){ redirect_to_next_step(); } );
    

    Facades are Models too (in my opinion), you may use them to hide wirings or complexities and reduce code-duplication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think the answer to this question is so obivous that noone has bothered
This is most certainly a language agnostic question and one that has bothered me
This one of the things that has always bothered me about Matlab. I understand
This has been a problem that I haven't been able to figure out for
This has happened to me 3 times now, and I am wondering if anyone
This has got to be something I just missed, but how do I add
This question has always bothered me. And the NetBeans wiki does not say anything
This has bothered me for awhile, and I have no clues if this is
This has always bothered me, and I've never really come up with my own
This has always bothered me... Let's say I have an interface IFiddle and another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.