Jump to content

Community

Developer Documentation

Building a controller for Content Items

Simply by being defined, a controller that extends \IPS\Content\Controller will inherit a lot of functionality.

Like all kinds of controllers, your content item controller belongs in the <app>/modules/<location> directory, such as yourapp/modules/front/somemodule/somecontroller.php

If you haven't already read about standard controllers in IPS4, I recommend you go there now and grasp the fundamentals before continuing. Content item controllers are simply a more specialized version of the standard dispatcher controller, and so most of the functionality remains the same, but with methods specific to content items also available.

 

Basic skeleton

At its most basic, a content controller is simply:

namespace IPS\yourapp\modules\front\yourmodule;

class _yourcontroller extends \IPS\Content\Controller
{

}

The key thing to note is that your controller extends \IPS\Content\Controller, rather than \IPS\Dispatcher\Controller directly.

Just by doing this, your controller already has the ability to delete content - if you append &do=delete&id=X (where X is the item ID) to the item URL, then the controller will automatically check if the user has permission to delete the item (which, by default, is only if the user is a moderator with permission to delete any content).

As you progress through the other steps of this guide, you'll implement other interfaces in your controller which will add new functionality (both automatic, and new methods you can call).

 


  Report Document


×
×
  • Create New...