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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:36:26+00:00 2026-05-27T05:36:26+00:00

I currently have a view, manage, that lists data items. Instead of running edit

  • 0

I currently have a view, manage, that lists data items. Instead of running “edit” and “add” actions with separate views, I’m having the appropriate form display inline in the page when it is needed. On the form is a “cancel” button that will hide it.

Right now I decide what, if any, form to display inline through a GET parameter called mode. So /controller/manage will display the items, while /controller/manage?mode=edit will display the items and show the edit form for the correct data item.

The action accepts various other GET parameters such as a date interval.

In order to activate the form, I’m generating a link to the current action with the mode parameter spliced in with existing parameters in $_GET. I’m using the following one-liner:

<?php echo CHtml::link('Edit', array_merge(array('/session/manage', 'mode' => 'edit', 'id' => 6), $_GET)); ?>

To implement the “cancel” link, I’m using:

<?php echo CHtml::link('Cancel', array_diff(array_merge(array('/session/manage'), $_GET), array('edit'))); ?>

My question is: is there a cleaner way to do this? While this works, it feels like a hack. I haven’t found any documentation on generating URLs that include existing GET parameters. Does Yii provide a built-in method to do what I want to do? Should I re-evaluate my general approach to conditional views, which might in turn yield a cleaner solution?

  • 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-27T05:36:27+00:00Added an answer on May 27, 2026 at 5:36 am

    One way would be to hold all of the most recent _GET variables in session state. Your controller would then act on that stored data and use new _GET variables to override it. Using that method, you wouldn’t need to merge the existing _GET variables back into the new request. The tradeoff is that you end up having to manage that session data and handle possible special cases (like starting over with fresh state).

    Another way would be to use Ajax to call an action that returns a partial view with your rendered edit form. Then your links would just need to call some javascript that does the Ajax call with the current ID and displays the returned form on the page. Your links would end up looking something like this:

    <a href="#" onclick="showEdit(6)">

    Since using Ajax wouldn’t cause the page to reload, you don’t need to worry about any of the _GET parameters required to show your list. And your Cancel link would become a javascript call to simply remove the edit form from the DOM. Using jQuery:

    $('#editform').remove();

    Another way to make it a little cleaner would be to encapsulate all of the array_merge() stuff up there into a method of a custom component or helper. Then your code could look something like:

    echo CHtml::link('Edit', URLHelper::mergeGet(array('/session/manage', 'mode' => 'edit', 'id' => 6));

    or even ecapsulate that in your own CHtml class:

    echo MyCHtml::link('Edit', array('/session/manage', 'mode' => 'edit', 'id' => 6));

    where MyCHtml::link() does everything that CHtml::link() does in addition to the array_merge stuff. MyCHtml could even extend CHtml so that it has all of CHtml’s methods.

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

Sidebar

Related Questions

We currently have a View that queries active directory info. I was wondering if
I currently have a list view which has several rows of data and I
I currently have a product view page that contains an MVCContrib HTML Grid with
1.I have a user that wants to view the current items version history on
I have some data that's currently stored in an Excel workbook. It makes sense
Currently I have a ListView (using the Details View). I would like to implement
I have created an Eclipse plugin which creates a view in Eclipse. Currently it
I have this layout that works correctly, a relative layout with a text view
I currently have an MS Access application that connects to a PostgreSQL database via
Currently I have tasked to prepare Document service for client side parser that user

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.