我試圖將$task數(shù)組和$str_pag變量傳遞給視圖。我嘗試將變量聲明$str_pag為公共變量,但視圖顯示一個數(shù)組,而變量則不顯示??刂破鱟lass 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; }
MVC:如何將數(shù)組和變量從模型傳遞到視圖?
慕田峪9158850
2023-09-22 15:23:00