1 users online. Create an account or sign in to join them.Users

Search

Hi to all symphonists.

I am having troubles coding a successful ajax page.

My goal is this: Try to extend the mailchimp extension in order to permits ajax request when submitting the form. My jQuery plugin for it works fine, but the ajax page always return an error:

Fatal error:  Call to a member function addStylesheetToHead() on a non-object in [...]/extensions/better_forms/extension.driver.php on line 30

You can find the code on github

If I disable the better_forms ext, I get the same error for other ext....

What am I doing wrong ?

Thanks in advance for any replies

This may be a problem with extensions that are not ready for latest version of Symphony.

It looks like Better Forms needs to update its __appendAssets() function to use Administration::getPageCallback() and/or check if Administration::instance()->Page instanceof HTMLPage (or $context['parent']->Page instanceof HTMLPage).

Update: looks like most of extensions does not check that. Maybe AjaxPage class used to extend HTMLPage? Why no one noticed that ajax pages started to show errors?

For a quick fix, you can try to implement dummy addStylesheetToHead and addScriptToHead functions to your custom AjaxPage class.

Also, i am not sure about the Frontend part. Why do you try to use AjaxPage there? It is meant to be used in the Administration area (backend).

You can extend mailchimp to use ajax calls from frontend by adding custom Event or DataSource and attach them to page created in Administration.

Update: looks like most of extensions does not check that. Maybe AjaxPage class used to extend HTMLPage?

I think it's just bad/poor development, especially on my behalf. ;P

Administration::instance()->Page instanceof HTMLPage

I'll add this check to Better Forms tomorrow. Thanks for reporting @Nitriques!

eKoeS, sorry, i have added new issue on github before noticing your answer here :(.

Wow, such responses in a short time span, especially on week end ,is super nice !!

@ahwayakchih: I used AjaxPage because this is exactly what I want... an ajax page... Why restrain this to the backend ?

I wanted to used this class because it did not require the user to create a new page in the CMS for handling the ajax request. So using a backend page for ajax request seem just ok to me, and I can even bypass the authorisation failed....

I based my work on a lot extension made by others. I checked the edui ext that uses and ajax page too. But his ajax request does not work either (just tested it)

@eKoes: It is (bad dev) ? so all of my ext are bad as well... And this is really weird as I was SURE that my issue was not related to your code since I got this error with a lot of other ext.

But my other question, why are ext called in an AjaxPage ?

@everybody: What should I do ? Change the class to extend FrontEnd ? XMLpage ? Try to patch all extensions I use ?? (I don't want that !!) I could add the dummy functions but that just seems a temporary fix to me... Maybe just used a simple php file like if I was coding without Symphony (plain php) ? But this would prevent me from usign the functionality existing in the mailchimp event. My goal is to keep all of the original extension 100% the same and just provide some way to fire the event via ajax request....

Thanks for all of your comments!

Hi to all!

I finally solve the problem by doing this

  1. Create a JSONPage class that extends Page; has a build method in order to comply with AdminPages
  2. Create my ajax content class that extends the JSONPage
  3. Fix my jQuery plugin

I welcome any code review, bug issue or any comments on my work!

To answer a couple of the previous questions, AJAXPage was designed to work in the backend context only, so it's ok that extensions aren't checking for Administration in this case, because it shouldn't be used in a Frontend context.

It's important to note that this page doesn't do anything Ajaxy at all, it's just a page that outputs XML. It's name comes from the context in which it's used (commonly) by extensions and the core in the backend.

@brendo: Thanks for you explanations... As I said I made my thing work extend the Page directly. Is this ok (good practice) ?

But I still wonder why some extensions break other AjaxPage ....

@ahwayakchih hit on the head, some extensions do not explicitly check that they are in the correct context before trying to append assets. In your case, the addStylesheetToHead and addScriptToHead functions don't exist in the AjaxPage context. You can see more of the differences by comparing the API between AjaxPage and AdministrationPage

The JSONPage is a clever approach, I don't see any problems with doing it that way.

(In the meanwhile, I have updated Better Forms)

@brendo, eKoes: Super thanks!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details