[TYPO3-project-formidable] Dynamically pass the cruser_id to the SQL of the datasource

Manuel Rego Casasnovas mrego at igalia.com
Thu May 8 11:55:50 CEST 2008


Hi,

On Thu, 2008-05-08 at 11:45 +0200, Ian Solo wrote:
> I have a renderlet:LISTER that get the data from this datasource:
> *****************************************************************
> <datasources>
> 	<datasource:DB name="images">
> 		<sql><![CDATA[
> 			SELECT	uid, image, title, tstamp, crdate
> 			FROM	tx_iangallery_gallery
> 			WHERE	pid = 301
> 			AND	cruser_id = 81
> 			AND	deleted=0
> 			AND	hidden=0
> 		]]></sql>
> 	</datasource:DB>
> </datasources>
> *****************************************************************
> 
> How can I dynamically pass the cruser_id of the current user logged to 
> this SQL?

You can use an userobj that return the SQL query from a function:
<datasource:DB name="images">
   <sql>
      <userobj>
         <extension>this</extension>
         <method>_generateSQL</method>
      </userobj>
   </sql>
</<datasource:DB>

or directly from PHP:
<datasource:DB name="images">
   <sql>
      <userobj>
         <php>
            <![CDATA[
               $cruserId = 81;
               return 'SELECT  uid, image, title, tstamp, crdate
                  FROM    tx_iangallery_gallery
                  WHERE   pid = 301
                  AND     cruser_id = ' . $cruserId . '
                  AND     deleted=0
                  AND     hidden=0';
                ]]>
         </php>
      </userobj>
   </sql>
</<datasource:DB>

Best regards,
   Rego

-- 
Manuel Rego Casasnovas
Computer Science Engineer
mailto:mrego at igalia.com
Tel: +34 986 10 76 10
Fax: +34 981 91 39 49
Igalia - http://www.igalia.com


More information about the TYPO3-project-formidable mailing list