开发者

I want to fetch data [closed]

开发者 https://www.devze.com 2023-02-11 14:19 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_StackOverflow Closed 11 years ago.

I want to fetch data from the data base but I don't know how to fetch data in Smarty. Please help me.


You fetch it like you would normally. You then "send" it to Smarty using $smarty->assign().

Like this:

$name = 'John';
$smarty = new Smarty();
$smarty->assign('firstname', $name);

In a Smarty template you can then use {$firstname} to access the data in $name:

<p>Hello, {$firstname}!</p>


Smarty is a Frontend templating engine. Though there are (lengthy) workarounds, you shouldn't attempt to access your model layer (the "data base") directly from a template. Rather, you should access the database information in PHP, then pass information into the smarty templates by assigning variables.


You dont fetch data in smarty... you only display data using smarty. Fetching data is done in your php page, and you assign the data array to a smarty variable, that displays the data in your .tpl file.

0

精彩评论

暂无评论...
验证码 换一张
取 消