Search

I’m trying to create my first backend content pages for an extension. Quite exciting! I’ve been poking about the innards of various extensions’ content pages to see what makes them tick, and I’ve had a good look at the AdministrationPage API doc. No matter what I try, however, I can’t seem to get different views working or use URL params.

Here’s what I have so far in content/content.index.php. If I go to symphony/extension/tag_manager/ I see what I would expect: a blank page with the correct title. If I go to symphony/extension/tag_manager/edit/, I get a “page not found” error. What am I doing wrong?

I saw other extension pages override the default __switchboard() method, and I confess I don’t really understand why one needs to do that. I tried doing so but it didn’t seem to have any effect.

Finally, how would I go about accessing URL params once I’ve got the content pages working? That is, if I visit symphony/extension/tag_manager/edit/articles/, I would want to pass the articles as a parameter to my edit view.

You're right, this isn't really explained in the API docs so it's a bit cryptic. The description for the switchboard method explains some of this:

        /**
     * The `__switchboard` function acts as a controller to display content
     * based off the $type. By default, the `$type` is 'view' but it can be set
     * also set to 'action'. The `$type` is prepended by __ and the context is
     * append to the $type to create the name of the function that will provide
     * that logic. For example, if the $type was action and the context of the
     * current page was new, the resulting function to be called would be named
     * `__actionNew()`. If an action function is not provided by the Page, this function
     * returns nothing, however if a view function is not provided, a 404 page
     * will be returned.
     *
     * @param string $type
     *  Either 'view' or 'action', by default this will be 'view'
     */

Some choose to override switchboard but you don't need to. What this method does is the role of controller/action routing. There are two "types" of actions (methods) that will be in your content pages: actions and views. An action is a method that is triggered usually by posting a form, and a view is the method that returns a page. By default a method named __viewIndex is called, so inside your content page create a method of this name and this will be called when you view your page at:

`/symphony/extension/extension_name/page_name/`

You can pass additional types as the first URL parameter, such as:

`/symphony/extension/extension_name/page_name/foo/`

To show the foo view, your method name would be __viewFoo.

Equally when you post something, this triggers an action. So if you post to your index, it would be handled by a method named __actionIndex, and if you posted to your foo page it would be handled by __actionFoo.

If you don't need any switchboard functionality and your page will always just show one view, then you can bypass all of this and just use methods named view and action instead.

In your example:

/symphony/extension/tag_manager/edit/articles/

This would require a page named content.edit.php with a method named view (or __viewIndex) and inside this you can get the URL param through the $context variable. I think $context is available only within a method named build, so I tend to capture the variables here, store as private members of the class, and then access them elsewhere:

https://github.com/nickdunn/search_index/blob/experimental/lib/class.search_index_administrationpage.php#L22-26

Is it possible to have;

/symphony/extension/extension_name/page_name/sub_page_name/foo/

go through to;

content.page_name.sub_page_name.php and run __viewFoo()

@vaughanhale: please don't post the same question twice. The answer is here.

@remie: sorry about that! Thanks for the help..

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details