Re: Smarty With Pear Datagrid
| From: | Olivier Guilyardi | Date: | Sat, 10 Jun 2006 10:20:47 +0000 |
| Subject: | Re: Smarty With Pear Datagrid | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24315@lists.php.net to get a copy of this message | ||
Hi Moses,
First, which version of Structures_DataGrid are you using ? Please use the CVS version if possible, not 0.6.3.
moses@softwaysolutions.com wrote:
I am using YDFramework in my applications which uses Smarty as its Template Engine.$datagrid =& new Structures_DataGrid (10,null ,DATAGRID_RENDER_SMARTY);which gives the following errorFailed opening required 'Smarty/Smarty.class.php'Now I downloaded Smarty and place it in my application folder. again I get the Following Error Fatal error: Cannot redeclare class smarty in D:\web\Moses\test\pear\DataGrid\Smarty\Smarty.class.php on line 65
The recommended way of using the Smarty renderer is this (You need the CVS version for this to work) : $datagrid =& new Structures_DataGrid(10); $datagrid->fill($smarty); where $smarty is a Smarty instance. The best, in you case, I suppose, would be to get the smarty instance that's internally used by the YDFramework. Reading : http://ydframework.berlios.de/doc/ydtemplate_syntax.html it looks like YDTemplate is a descendant of Smarty, or implements the same interface. So you might : $template = new YDTemplate(); $datagrid->fill($template); Note : fill() might not detect that $template is a $smarty compatible object. In this case you will need to set the type : $datagrid->fill($template, array(), DATAGRID_RENDER_SMARTY); After calling fill(), new variables and functions will be available in your templates. Please the "GENERAL NOTES" section at the top of DataGrid/Renderer/Smarty.php for detailed informations about this.Since YDFramework is coupled with smarty it already initialize the Class Smarty so the class can be redeclared.Now what to do.
Again
I tried with working with creating the instance of datagrid without passing the parameter DATAGRID_RENDER_SMARTY $datagrid =& new Structures_DataGrid (10);
Now I dont get any error and I am passing the Datagrid object to the smarty template and its working Fine.
I don't really understand what you mean by "passing the Datagrid object to the smarty template".
I want to clarify some doubts...Normally you don't need to use the DATAGRID_RENDER_SMARTY constant. fill() is able to auto-detect the type of the container that you pass to it. But if you use a "smarty compatible" object, as YDTemplate might be, then you need to specify the type as shown above.1) Is there any particular reason or use to Pass the argument DATAGRID_RENDER_SMARTY while using Smarty.
Because you are using DATAGRID_RENDER_HTMLTABLE which is the default renderer used by the datagrid. It generates HTML, and I suppose you manage to paste it into your Smarty templates. But, for sure, that's a bad practice because you handle presentation through external code, when you're supposed to do that using Smarty templates, Smarty variables, etc.... Please take a look at the GENERAL NOTES section of DataGrid/Renderer/Smarty.php, from the CVS version. Smarty support in Structures_DataGrid has been much improved. Regards, -- og2) Though I am not using the argument its is working. Why!!!!