Page 1 of 1

using CreateInputSelectList

Posted: Mon Apr 27, 2009 3:31 pm
by rlparker25
I am trying to create a module where you can create pieces of content and then select from a list which pages you want it to appear on.

I have everything working except the select list. This is the code I am using

Code: Select all

//create array of all the active pages
$myquery = "SELECT * FROM cms_content WHERE active=1";
$myresult = $db->Execute( $myquery );

$pagearray = array();
while ($myresult && $myrow = $myresult->FetchRow())
{
 	$pagearray[$myrow['content_name']] =  $myrow['content_id'];
}
 
$selpages = explode(',',$row['pages']);// this creates an array of page ids that are stored in the database in a field called pages
$selpagearray = array();
for ($i=0; $i <sizeof($selpages); $i++) 
{
	$query2 = 'SELECT content_name FROM cms_content WHERE content_id = '.$selpages[$i];
                $row2 = $db->GetRow($query2);
	$selpagearray[$row2['content_name']] = $selpages[$i]; // build array of pages that should be selected
}
 
$this->$smarty->assign('inputpages', $this->CreateInputSelectList($id,'pages[]',$pagearray,$selpagearray)); 
$this->smarty->assign('pagestext', $this->Lang('pages')); 
When I dump the two arrays I create this is what I get

array(5) { ["Home"]=> string(2) "15" ["test form"]=> string(2) "16" ["podcast"]=> string(2) "17" ["events"]=> string(2) "18" ["gallery"]=> string(2) "23" }

array(2) { ["Home"]=> string(2) "15" ["podcast"]=> string(2) "17" }

and this is the error I am getting

Catchable fatal error: Object of class Smarty_CMS could not be converted to string in /home/bible/SQ32P4N3/htdocs/modules/YMABII/action.editContent.php

it doesn't seem to matter what array I put into the function I still get the same error. Could someone please tell me where I am going wrong or give me a working example?

Thank you

Rachael

Re: using CreateInputSelectList

Posted: Mon Apr 27, 2009 3:49 pm
by calguy1000
uhm... simple mistake:

Code: Select all

$this->$smarty

Re: using CreateInputSelectList [solved]

Posted: Mon Apr 27, 2009 3:52 pm
by rlparker25
d'oh!

thank you, you're a star!!!

Re: using CreateInputSelectList

Posted: Mon Apr 27, 2009 3:53 pm
by calguy1000
BTW.

I wouldn't rely on $this->smarty at all.
one of these days the smarty member is gonna be removed from the module.... it's redundant

$smarty is available in all module actions
and if it's not you can always do a:

Code: Select all

global $gCms;
$smarty =& $gCms->GetSmarty();