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

  • SEARCH
  • Home
  • 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 977735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:56:56+00:00 2026-05-16T03:56:56+00:00

Avoiding Fat Controller So I’m using Zend Framework and I have a question involving

  • 0

Avoiding Fat Controller

So I’m using Zend Framework and I have a question involving preventing fat controllers with one of my actions. Basically I am normalizing a CSV file into my database.

This means that I have to get the feed and then use my model.
The feed grabbing is just there to show how it works, but that is now an Action Helper.

I am using the Data Mapper pattern with Zend Framework. I hate that I am doing this in my Controller. All of those setProperty()->setProperty()->setProperty() look incredibly fugly and I feel like I am doing it in the wrong place? Would it be a better option to just create some kind of service layer where I pass the entire $feed and then in that class I instantiate my Models and my Mapper?

Also, I need to normalize, which means I should be using a transaction, but I’m unsure where I should start my transaction. Because of the way I am doing things currently, the only place I could ever consider is in my Controller. wow.. that would be an awful place.

How can I get the model behaviour and operations out of my controller?

ImportController.php

public function indexAction() {
        $start = $this->getRequest()->getParam('start');
        $end = $this->getRequest()->getParam('end');
        $url = "http://www.domain.com/admin/GetBookingData.aspx";       

        $client = new Zend_Http_Client();
        $client->setParameterGet('dateEnteredMin', $start);
        $client->setParameterGet('dateEnteredMax', $end);
        $client->setParameterGet('login', 'login');
        $client->setParameterGet('password', 'password');
        $client->setUri( $url );
        $client->setConfig(array(
            'maxredirects' => 0,
            'timeout'      => 30));
        // Send the request. 
        $response = $client->request();

        // Grab the feed from ->getBody and add it to $feed
        $feed = $this->csv_to_array(trim($response->getBody()));


        // The first item in the array is the heading in the CSV, so we can remove it from the array using shift().
        $title = array_shift($feed);

        // Create my Models and Mappers.
            // ***  EVERYTHING BELOW HERE IS WHAT I DON'T LIKE ***
        $bookings =         new Bookings_Models_Bookings();
        $property =         new Bookings_Models_Property();
        $clients =      new Bookings_Models_Clients();

        $bookingsMapper =   new Bookings_Models_Bookings_Mapper();
        $propertyMapper =   new Bookings_Models_Property_Mapper();
        $clientsMapper =    new Bookings_Models_Clients_Mapper();

        $bookings->setId($feed[9])
            ->setPropertyId($feed[1])
            ->setClientId($feed[2])
            ->setDate($feed[4]);
        $bookingsMapper->save($bookings);

        $property->setId($feed[1])
            ->setPropertyName($feed[23])
        $propertyMapper->save($bookings);

        $clients->setId($feed[2])
            ->setFirstName($feed[20])
            ->setLastName($feed[21])
        $clientsMapper->save($clients);

}
  • 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-16T03:56:56+00:00Added an answer on May 16, 2026 at 3:56 am

    Service layer is probably the way I’d go. So you’d create a service class that looks something like this:

    class Your_Service_Import
    {
        public function importFromCsv($csv)
        {
            // etc.
        }
    }
    

    you’d then move all of your controller method code that’s after the csv_to_array call into that method, leaving the end of your controller method looking something like this:

    $feed = $this->csv_to_array(trim($response->getBody()));
    
    $service = new Your_Service_Import();
    $service->importFromCsv($feed);
    

    This makes it easier to test your import code (since it’s in a standalone class) and easier to reuse in other parts of your application.

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

Sidebar

Related Questions

I have asked a question about how to avoiding to write the html in
Thinking about avoiding code replication, I got a question that catches me every time
I am avoiding the creation of files on disk, this is what I have
My question is about avoiding namespace pollution when writing modules in R. Right now,
just wondering what tips people have for avoiding game synchronisation issues in multiplayer games
This question is about good programming practices and avoiding potential holes. I read Joshua
How can i forward to other action inside the same controller avoiding repeat all
I've read a few other posts like this one about avoiding repetition in Java
Question: What are some other strategies on avoiding magic numbers or hard-coded values in
I want to gather a fairly complicated wrapped set using JavaScript whilst avoiding having

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.