我试图将$task数组和$str_pag变量传递给视图。我尝试将变量声明$str_pag为公共变量,但视图显示一个数组,而变量则不显示。
控制器
class Index extends Controller{
public function __construct() {
parent::__construct();
require 'views/header.php';
require 'models/index_model.php';
}
public function index() {
$tasks = Index_Model::index($id, $login, $email, $password);
require 'views/index/index.php';
require 'views/footer.php';
}
}
模型
class Index_Model extends Model
{
public $str_pag;
public function index($id, $login, $email, $password)
{
$db = new Database();
if (isset($_GET['page'])){
$page = $_GET['page'];
}else
$page = 1;
$total = Index_Model::getCount();
$kol = 3;
$art = ($page * $kol) - $kol;
$str_pag = ceil($total / $kol);
$stm = $db->prepare('SELECT * FROM users LIMIT ?,?');
$stm->bindValue(1, $art, PDO::PARAM_INT);
$stm->bindValue(2, $kol, PDO::PARAM_INT);
$stm->execute();
$task = array();
$i=0;
while($row=$stm->fetch()) {
$task[$i]['name'] = $row['name'];
$task[$i]['email'] = $row['email'];
$i++;
}
return $task;
}
RISEBY