Develop a simple package in concrete.

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
May 18, 2016

So now we will start work on a package.

1) Create the package directory

First of all, create a directory in the package directory of your application. Your directory name should be whatever your package name is. I will use the directory name sample_package. So now you have the directory structure Concrete/Package/sample_package. Here, concrete is my application name.

2) Create the controller

Create a file in Concrete/Package/sample_package named controller.php. This file will be responsible for installation, uninstall, upgrade, and other functionalities.

Here is sample code:

<?php 

namespace Concrete\Package\SamplePackage;

use Package;

/**
 * This is the main controller for the package which controls the  functionality like Install/Uninstall etc.
 * 
 * @author AN 05/16/2016
 */
class Controller extends Package
{

    /**
     * Protected data members for controlling the instance of the package 
     */
    protected $pkgHandle = 'sample_package'; 
    protected $appVersionRequired = '5.7.5.6';
    protected $pkgVersion = '0.0.1';

    /**
     * This function returns the functionality description ofthe package.
     * 
     * @param void 
     * @return string $description
     * @author AN 05/16/2016
     */
    public function getPackageDescription()
    {
        return t("A package to demo of package development.");
    }

    /**
     * This function returns the name of the package.
     * 
     * @param void
     * @return string $name
     * @author AN 05/16/2016
     */
    public function getPackageName()
    {
        return t("sample package");
    }

    /**
     * This function is executed during initial installation of the package.
     * 
     * @param void
     * @return void
     * @author AN 05/16/2016
     */
    public function install()
    {
        $pkg = parent::install();

        // Install Single Pages
        $this->install_single_pages($pkg);
    }

    /**
     * This function is executed during uninstallation of the package.
     * 
     * @param void
     * @return void
     * @author AN 05/16/2016
     */
    public function uninstall()
    {
        $pkg = parent::uninstall();
    }

    /**
     * This function is used to install single pages.
     * 
     * @param type $pkg
     * @return void
     * @author AN 05/16/2016 
     */
    function install_single_pages($pkg)
    {
        $directoryDefault = SinglePage::add('/dashboard/sample_package/', $pkg);
        $directoryDefault->update(array('cName' => t('Sample Package'), 'cDescription' => t('Sample Package')));
    }

}

So you can see there are some basic functions defined in this controller. Don't be confused to see install_single_pages functionality. I will describe it later. So copy this code into your controller.php and save it.

3) Give an icon to your package

If you want (and it's recommended), give your package an icon. It is so easy: Put a 97px X 97px .png image in your package folder (Concrete/Package/sample_package). You must name this image icon.png.

4) Create a directory structure for the controller

Create this directory structure for your controller file:

Concrete/Package/sample_package/controller/single_page/dashboard

Then create a file with the name sample_package.php in the dashboard directory and put this code:

<?php

namespace Concrete\Package\SamplePackage\Controller\SinglePage\Dashboard;

use \Concrete\Core\Page\Controller\DashboardPageController;

defined('C5_EXECUTE') or die(_("Access Denied."));

/**
 * This is the controller for the package which controls the functionality for /dashboard/database/ route.
 * 
 * @author AN 05/16/2016
 */
class SamplePackage extends DashboardPageController
{

    /**
     * Function to set the variables for view.
     * 
     * @param void
     * @author AN 05/16/2016
     */
    public function view()
    {
        // Here you can set variable for view $this->set('nameForView',$variable);
    }
}

5) Create a directory structure for single pages

Create this directory structure for the controller file: Concrete/Package/sample_package/single_page/dashboard/sample_package

Next, create a file with name view.php in the dashboard directory and put any html code.

Example:

Hi Sample package

Now install the package and you will get a menu option "sample package". Click it or add this url after index: /dashboard/sample_package. Your page will be shown. You can customize this according your need.

Let me know if this post need any improvement and have any error.

Thanks.

Recent Tutorials
Using the Concrete Migration Tool Addon
Apr 27, 2023

How to use the Concrete CMS Migration Tool

How To Add Page Last Updated To Your Concrete CMS Pages
Mar 7, 2023

Concrete CMS has a page attribute you can add to a global area called "Page Date Modified." Here's how to add it

How To Exclude Subpages from Navigation
Dec 24, 2022

How to exclude subpages from navigation - useful for a news or blog link in your main navigation where you don't want all the subpages to appear in a drop down menu.

How Can I Change The Maximum Size Of Uploaded files
Dec 13, 2022

This tutorial explains how to update your php settings.

Updating Concrete Themes from Version 8 to Version 9
Nov 24, 2022

This tutorial covers commonly encountered issues when upgrading a Concrete CMS theme from version 8 to version 9

Transferring ownership of an add-on and a theme
Nov 15, 2022
By katzueno.

If you encounter a Concrete CMS add-on or theme that you love but not being maintained, you may want to ask the author to help or take over the add-on or theme. Here is the quick step-by-step guide of how to transfer the ownership.

Was this information useful?
Thank you for your feedback.