History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-3162
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Carlton Gibson
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

AjaxContext requires format parameter even when only one format is allowed (This is redundant.)

Created: 22/Apr/08 03:14 AM   Updated: 03/Sep/08 12:00 AM
Component/s: Zend_Controller
Affects Version/s: 1.5.1
Fix Version/s: Next Minor Release

Time Tracking:
Original Estimate: 1 hour
Original Estimate - 1 hour
Remaining Estimate: 1 hour
Remaining Estimate - 1 hour
Time Spent: Not Specified
Remaining Estimate - 1 hour

Fix Version Priority: Should Have


 Description  « Hide
With the Action Helper, AjaxContext you often only provide one alternate context format. The switch to this context is triggered via the detection of the isXmlHttpRequest() member of the request object. However, currently one also has to supply a format parameter with the request. This seems redundant.

I copy a thread from the MVC list below. This shows that it is fairly trivial to extend AjaxContext to automatically check is there is just one context and if so use it.

My thought though is that it may be nice to work this feature into the base ContextSwitch class. The idea would be that the first context format given would be the default, which would be applied if no format string was given, whereas the later formats would require you to provide the format parameter.

On 16 Apr 2008, at 21:25, Taylor Barstow wrote:

On Apr 11, 2008, at 10:10 AM, Taylor Barstow wrote:

When using the AjaxContext helper, it seems odd to me that I have to add ?format=X to my URIs in order to trigger the context switch, especially if I have only specified one possible format.

Shouldn't the X-Requested-With: XMLHttpRequest header be enough? Is there any way that I can trigger the context switch without passing the format parameter when there is only one possible format?

To follow up on this, I looked further into it and you can actually make this happen yourself:

class MyController extends Zend_Controller_Action {

public $ajaxable = array('index' => array('html'));

public function init()

Unknown macro: { $this->_helper->ajaxContext->initContext('html'); }

}

BIG CAVEAT: You would only want to do this if you only have one context format for the entire controller.

I hope this helps someone else

Taylor

Following on from this suggestion, I think the following should allow us to forgo specifying the format parameter whilst still allowing multiple contexts within a single controller.

(I wasn't able to find a feature request for this sort of change to AjaxContext. Do people think it is worth filing one?)

Regards,
Carlton

<?php
/**

  • Removes need to specify format param when providing unique ajax context.
    */
    class My_Controller_Action_Helper_UniqueAjaxContext extends Zend_Controller_Action_Helper_AjaxContext
    {
    /**
  • Automatically initialise unique AjaxContext on a per action basis.
    */
    public function initContext($format = null)
    {
    $action = $request->getActionName();
    $context = $this->getActionContexts($action)

//check in case multiple contexts DO exist
if(count($context) === 1)

Unknown macro: { $format = $context[0]; }

return parent::initContext($format);
}



 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Matthew Weier O'Phinney - 09/May/08 11:17 AM
Scheduling for next minor release