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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:13:25+00:00 2026-05-31T09:13:25+00:00

I have and add/edit form that adds/edits depending on whether there is an id

  • 0

I have and add/edit form that adds/edits depending on whether there is an id passed.

This model is accessed by three different types of users in 3 completely different situations – different controllers, different menus, different breadcrumbs, different everything. Yet, the form is the same, the logic is the same.

So essentially I have 2 problems – repeating view form and repeating controller code.

I tried to put it in a element, but then I have to pass a variable for the action of the form to point to different controllers. And if i have the same action and use the same controller, then I have to have some kind of referer() and it’s almost impossible to pass all the different data for breadcrumbs, menus, sidebars etc. i am missing something major in planning it out.

How should I organize my code with the idea to have minimum code and minimum overhead since my app is changing by the day, and i don’t want to be updating 3 places and forget some of them etc.

  • 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-31T09:13:26+00:00Added an answer on May 31, 2026 at 9:13 am

    You can reuse controller logic by creating a component (or by placing logic in AppController):

    // controllers/first_controller.php
    class FirstController extends AppController {
    
        public $components = array('MyForm');
    
        public function firstAction($id = null) {
            $this->MyForm->processForm(/* params */); // inserts reusable logic
            $this->redirect(array('action' => 'index'));
        }
    }
    

    (Repeat for SecondController::secondAction() and ThirdController::thirdAction().)


    You can reuse view logic by creating elements:

    // views/first/first_action.ctp
    $this->Html->addCrumb('First');
    echo $this->Html->tag('h2', 'First');
    $this->element('my_form', array(/* params */)); // inserts reusable logic
    

    (Repeat for other views.)


    I tried to put it in a element, but then I have to pass a variable for the action of the form to point to different controllers.

    You can access $this->params from inside an element, saving you from having to pass in trivial things like the current action.

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

Sidebar

Related Questions

I have a jqGrid that has add/edit dialogs with a form that's longer than
I have a simple form where a user can add, edit, and delete people
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,
I have a form that allows a user to add an unlimited number of
We have a web application that is based around a form that gets passed
I have a Django form that will add an entry to a database with
I have a webpage with a form that is used to edit some object.
I have used hook_form_FORM_ID_alter( ) function to alter a menu_edit_menu form to add few
I have a edit in place section to which I want to add a
I have Excel add-in which I add so many class modules that it is

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.