News:

AbanteCart v1.4.2 is released.

Main Menu

Problem with dispatch

Started by dhigz, December 16, 2015, 01:25:20 AM

Previous topic - Next topic

dhigz


Looking for developer help. I am working on a new extension and ran into a problem with the dispatch command.

In my extensions core file, I have the function: onControllerCommonSeoUrl_InitData(). I have a need for one page to execute a custom url different the the standard url output format generated by seo_url.php. This is the code I have:


public function onControllerCommonSeoUrl_InitData(){
                if (isset($this->baseObject->request->get['_route_'])) {
$parts = explode('/', $this->baseObject->request->get['_route_']);
if($parts[0] == 'my_page_name') {
$this->request->get['m'] = $parts[1];
$this->request->get['y'] = $parts[2];
$rt = 'pages/XXXX/archive';
                                //name removed - don't want to say what the extension is yet

                                 unset($this->baseObject->request->get['_route_']);
                                 //this prevents the script in the base file (seo_url.php) from processing any other data
                                 
                                // The next two lines come from the end of seo_url.php       
//This line works
$this->baseObject->router->resetController($rt);

                               // This is where the problem is...
  return $this->dispatch($rt,$this->request->get);


}else{

foreach ($parts as $part) {

                                 //continues ........
 

return $this->dispatch($rt,$this->request->get);
Dispatch does run but returns the correct layout for my page with blocks from the intended page and my index page.   

I tried inserting baseObject as you should in an extension core file:   
return $this->baseObject->dispatch($rt,$this->request->get);
This returns a blank page with the logged error:  error: AbanteCart core v.1.2.2 Call to protected method AController::dispatch()  from context 'ExtensionXXXXX'....

The page will load if I use the standard format non-seo url. It will also load if I use a RewriteRule in my .htaccess file (trying to avoid this). The values for dispatch route are correct ($rt = 'pages/XXXX/archive') and the values in the array are valid and correct. Values are correct in the block_layout table.

Any suggestions on what I need to do to get dispatch to properly run?
Don Higbee

yonghan

Hi, I think you can copy the dispatch function from the core code into your hook file, make it as a private function and then call the dispatch with $this->dispatch(xxxx). Hope it helps.

dhigz

Thanks for the input. It didn't work but it did lead me to discovering my problem was much deeper.

Thanks.
Don Higbee

Forum Rules Code of conduct
AbanteCart.com 2010 -