Develop a simple package in concrete.

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
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.

How to update Add-Ons if not on the Update Add-Ons Menu item
Jul 4, 2022

How to manually download an add-on and update it when your site's core versions isn't considered compatible with the add-on version.

Generate a report with author information and form summaries in Concrete CMS.
May 9, 2022

In Concrete CMS, you can use a form to initiate contact between logged-in users and then create helpful reports. After form submissions are collected, they can be searched, sorted, and exported as a spreadsheet. This tutorial will detail how to add author information to a report using the advanced search.

How to clone and customize Atomik theme
Feb 14, 2022
By linuxoid.

How to clone and customize Atomik theme

Update jQuery to 3.5 on Concrete CMS version 8.5.x
Dec 1, 2021
By hissy.

If you have to take some time to fix your site to work with version 9 and want to update jQuery immediately, you can override it.

Was this information useful?
Thank you for your feedback.