Concrete 5.7 addon development
Permalink
I want to create an addon for concrete 5.7. Where there will be two views for adding texts. For this in main controller I have witten
$page1 = SinglePage::add('/dashboard/my_custom_texts', $pkg);
$page1->updateCollectionName(t('My custom List'));
$page2 = SinglePage::add('/dashboard/my_custom_texts/my_custom_textscat', $pkg);
$page2->updateCollectionName(t('My Category List'));
In concrete/packages/my_custom_texts/controllers/single_page/dashboard/my_custom_texts/my_custom_textscat.php
I have written
In concrete/packages/my_custom_texts/src/Textcat.php
I have written
In concrete/packages/my_custom_texts/src/TextcatPageList.php
I have written
In concrete/packages/my_custom_texts/src/TextcatSingleList.php
I have written
But in view
concrete/packages/my_custom_texts/single_pages/dashboard/my_custom_texts/my_custom_textscat.php
when I am writting
It is showing error Invalid argument supplied for foreach().
Need help to fix this.
$page1 = SinglePage::add('/dashboard/my_custom_texts', $pkg);
$page1->updateCollectionName(t('My custom List'));
$page2 = SinglePage::add('/dashboard/my_custom_texts/my_custom_textscat', $pkg);
$page2->updateCollectionName(t('My Category List'));
In concrete/packages/my_custom_texts/controllers/single_page/dashboard/my_custom_texts/my_custom_textscat.php
I have written
<?php namespace Concrete\Package\MyCustomTexts\Controller\SinglePage\Dashboard; use \Concrete\Core\Page\Controller\DashboardPageController; use Loader; use \Concrete\Package\MyCustomTexts\Src\TextcatPageList; defined('C5_EXECUTE') or die(_("Access Denied.")); class MyCustomTextscat extends DashboardPageController { public $helpers = array('form'); public function view() { $ctextList = new TextcatPageList(); $ctextList->setItemsPerPage(25); $paginator = $ctextList->getPagination(); $pagination = $paginator->renderDefaultView(); $this->set('textslist',$paginator->getCurrentPageResults());
Viewing 15 lines of 19 lines. View entire code block.
In concrete/packages/my_custom_texts/src/Textcat.php
I have written
<?php namespace Concrete\Package\MyCustomTexts\Src; use Concrete\Core\Foundation\Object as Object; use Database; use Concrete\Package\MyCustomTexts\Src\TextcatArrayList; defined('C5_EXECUTE') or die(_("Access Denied.")); class Textcat extends Object { public static function getByID($sID) { $db = Database::get(); $data = $db->GetRow("SELECT * FROM btmycustomtextcat WHERE sID=?",$sID); if(!empty($data)){ $ctext = new Textcat(); $ctext->setPropertiesFromArray($data); }
Viewing 15 lines of 18 lines. View entire code block.
In concrete/packages/my_custom_texts/src/TextcatPageList.php
I have written
<?php namespace Concrete\Package\MyCustomTexts\Src; use Database; use Concrete\Core\Search\Pagination\Pagination; use Concrete\Core\Search\ItemList\Database\ItemList as DatabaseItemList; use Pagerfanta\Adapter\DoctrineDbalAdapter; use Concrete\Package\MyCustomTexts\Src; use Concrete\Package\MyCustomTexts\Src\Textcat; class TextcatPageList extends DatabaseItemList { public function createQuery() { $this->query ->select('t.sID') ->from('btmycustomtextcat','t') ->orderBy('sortOrder', 'ASC');
Viewing 15 lines of 35 lines. View entire code block.
In concrete/packages/my_custom_texts/src/TextcatSingleList.php
I have written
<?php namespace Concrete\Package\MyCustomTexts\Src; use Database; use Concrete\Core\Search\Pagination\Pagination; use Concrete\Core\Search\ItemList\Database\ItemList as DatabaseItemList; use Pagerfanta\Adapter\DoctrineDbalAdapter; use Concrete\Package\MyCustomTexts\Src; use Concrete\Package\MyCustomTexts\Src\Textcat; class TextcatSingleList extends DatabaseItemList { public function createQuery() { $this->query ->select('t.sID') ->from('btmycustomtextcat','t') ->orderBy('RAND()', 'DESC')
Viewing 15 lines of 36 lines. View entire code block.
But in view
concrete/packages/my_custom_texts/single_pages/dashboard/my_custom_texts/my_custom_textscat.php
when I am writting
<?php foreach ($textslist as $tl) : ?> <?php echo($tl->sID)?> <?php endforeach;?>
It is showing error Invalid argument supplied for foreach().
Need help to fix this.
There is nothing glaringly obvious here, you will need to go through your package and put echo statements in key places to make sure that the right functions are called and return what you expect.
Hello hutman,
In concrete/packages/my_custom_texts/controllers/single_page/dashboard/my_custom_texts/my_custom_textscat.php I wrote
even that is also not displaying.
In concrete/packages/my_custom_texts/controllers/single_page/dashboard/my_custom_texts/my_custom_textscat.php I wrote
public function view() { echo "Show my custom texts";
even that is also not displaying.
Have you changed any of your file structure/paths since you installed the package? The correct paths/namespaces must be in there before installation or they won't work. Also, do you have all caches turned off and debugging turned on?