how to Install Page Type

I want to create page type via controller.php and below code is working in 5.6...

$ct = CollectionType::getByHandle('home');
if((!is_object($ct)) || ($ct->getCollectionTypeID() < 1)) {
$data['ctHandle'] = 'home';
$data['ctName'] = t('Home');
$hpt = CollectionType::add($data, $pkg);

What do i do for 5.7

Please help and tell alternative way with example

View Replies: View Best Answer
PineCreativeLabs replied on at Permalink Best Answer Reply
The code you're using is considered deprecated in 5.7+. The code I have below is intended for 8.x, but it works with 5.7.x as well. Here's what you'll need for your package controller:

use Concrete\Core\Page\Theme\Theme;
use PageTemplate;
defined('C5_EXECUTE') or die("Access Denied.");
class Controller extends Package {
public function install() {
        $pkg = parent::install();
private function pageTemplates($pkg) {
        if (!PageTemplate::getByHandle('home')) {
            PageTemplate::add('home, t('Home') $pkg);

Notice the private function for creating the page type, and it's checking to see if it already exists and if not, create it.