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.
精彩评论