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 4565220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:36:43+00:00 2026-05-21T18:36:43+00:00

I have a controller that creates a sidebar. In the middle of the sidebar

  • 0

I have a controller that creates a sidebar. In the middle of the sidebar is a small section of patient data that needs to be refreshed via ajax from time to time. So, I created an element and a function for that specific area. I use a requestAction to get the patient data for the element when I’m rendering the entire sidebar. But, when I’m doing an ajax request, I call the patient data function directly and return it’s view. Ajax then loads the div with the data from the view.

My dissatisfaction is that I now have the same exact view code in two places. Once In the view and once in the element. Ideally, I’m sure that I should be using the element for both. I guess I could create another function for the ajax request to call, that would simply do a requestAction to get the element data. But, that seems like an unnecessary extra layer.

In Xaraya, I would have avoided this all by simply using the patient data view within the sidebar view.

How should I be handling this to most efficiently re-use the same code?

  • 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-21T18:36:44+00:00Added an answer on May 21, 2026 at 6:36 pm

    You are right be be bothered by duplicate code. Move everything to the element. Call the element from ALL locations where you need it. Configure it to work in both circumstances. So basically, replace the view instance to call the element as well. You are right about that.

    It appears your hangup is the “unnecessary extra layer.” However, if it keeps the code clean (by removing duplicate code) is it really an unnecessary extra layer? I would say no. It make it reusable in multiple locations, therefore very much necessary.

    Sounds like you should trust your instincts. 😉

    Happy coding!

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

Sidebar

Related Questions

I have a controller that is called with AJAX (sends JSON data), so I
I have a modal view controller that creates core data changes in it's own
In a word, how? I have a view controller that creates a few custom
I have a controller that runs some calculation on data, and then I need
--Summary (shortened)-- I have a controller that loads a profile object from the corresponding
I have a method that creates a form in my controller: ... sbReturn.Append(String.Format(<p id='planSetupAddNewEffectiveDate'>));
I'm creating a custom controller generator that derives from Rails::Generators::NamedBase that creates both a
I have the following code that creates a modal navigation controller and presents it.
In my app, I have a table view controller that creates a couple of
I am using cakephp 2.1.0 I have a Post Controller that basically creates a

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.