sitecrafting / conifer

:evergreen_tree: A powerful WordPress library plugin for OO development
https://www.coniferplug.in
MIT License
18 stars 2 forks source link

Conifer Docs Update to AjaxHandler Example #104

Closed dknoben closed 5 years ago

dknoben commented 5 years ago

The first AjaxHandler Class example will not work becuase the execute function does not match the abstract base execute class.

Expected behavior

When I run an ajax call, the class returns the data array

Actual behavior

I get a 500 error.

PHP Fatal error:  Declaration of Theme\AjaxHandler\MyAjaxHandler::execute() must be compatible with Conifer\AjaxHandler\AbstractBase::execute(): array in /app/wp-content/themes/Theme/lib/Theme/AjaxHandler/MyAjaxHandler.php

Solution

If you can update the example of the execute function to include the array return type, that would stop the issue.

protected function execute() : array {
   /* 
    * Your custom logic goes here
    * Request data is accessible via $this->request
    * Return an array with the appropriate response data
    */
    return ['example' => 'data'];
  }
acobster commented 5 years ago

Fixed in https://github.com/sitecrafting/conifer/commit/5dba6e3eb9b98da8cd432697fd8dc5c2cf51e458.