SoFunction
Updated on 2025-03-10

How to add foreach-like functions to automatically load data in smart


/**
* Loading data
* @param $tag_args
*/
function _complie_load_start($tag_args)
{
$key = substr(md5($tag_args), 8, 16); // Generate a special variable name based on the parameters
 $attrs = $this->_parse_attrs($tag_args);
// More processing can be added here
 $class = (!isset($attrs['class']) || empty($attrs['class'])) ? 'cls_crud' : trim($attrs['class']);
 (!isset($attrs['table']) || empty($attrs['table'])) && exit('`table` is empty!');
 $db = $class::factory(array('table' => substr($attrs['table'], 1, -1)));
//Define new variables
 $this->_tpl_vars[$key] = $db->get_block_list(array(substr($attrs['where'], 1, -1)), $attrs['limit']);
 $tag_args = "from=/${$key} " . $tag_args;

//Calling the foreach tag processing function for processing
 return $this->_compile_foreach_start($tag_args);
}