creating action urls from within an action handler over AJAX

Permalink 1 user found helpful
Hi,

I am currently writing a package that displays an action into an AJAX dialog.

Within that ajax dialog, I wish to refresh the content of that dialog, and load this content from another action.

Now start my problems : I can not access to BlockView::action since I am running into a BlockController directly ... so far, I can handle it differently, looking at the relevant part of BlockView::action, i just create a passthru url using the BlockController::getBlockPassThruAction method, and appending a "&methd=$task" ... ok so far so good, but that actually does not work :(

Checking at concrete/startup/process.php, I find this :

case 'passthru':
            if (isset($_GET['bID']) && isset($_GET['arHandle'])) {


ahhaa!! nailed you ! process.php checks that the 'arHandle' is set in the _GET request. can do, I create my personnal MyBlockController::action method :

public function action( $task )
   {
      $block = $this->getBlockObject();
      $arHandle = $_REQUEST['arHandle']; // needed to get a passthru call
      return $block->getBlockPassThruAction() . "&arHandle=$arHandle&method=on_button_clicked";
   }


(btw, I got had with that once, those needs to be html_entity_decode from the php script if you intend to use it directly to generate a javascript script).

and, tadaaaa ! is works perfectly .... that is ... as long as my block is not within a stack :/, ok, some more dig in and still in the process.php (actually next case block) :

case 'passthru_stack':
            if (isset($_GET['bID'])) {
               $vn = Loader::helper('validation/numbers');
               if ($vn->integer($_GET['bID'])) {
                  $b = Block::getByID($_GET['bID'], Page::getByID($_REQUEST['stackID'], 'ACTIVE'), STACKS_AREA_NAME);


argl !! passthru gets called differently if the block is in a Stack :-X, hence the arHandle is not passed in the initial request …

and that's pretty much where I am stuck, I can go ahead and add some more ugly hack, (like copying the stackID out of request, and then changing the 'passthru' key in the generated URL to 'passthru_stack' (regexp is my friend), or just setting a random arHandle (since it seems completely useless from the action point of view), but hey, this is really starting to look ugly there).

Can somebody point me a less hackish way of doing things ?

 
goutnet replied on at Permalink Best Answer Reply
For those who may have a similar issue, I got it to work by changing my action method to this :

public function action( $task )
   {
      $block = $this->getBlockObject();
      $arHandle = isset( $_REQUEST['arHandle'] ) ? $_REQUEST['arHandle'] : 42; // needed to get a passthru call
      return $block->getBlockPassThruAction() . "&arHandle=$arHandle&method=on_button_clicked";
   }


Basically, if I can't get a valid arHandle, I just make it up. Since the only use of arHandle is a sanity check in process.php, it works (clean or not :/).