私の基本的な PHP codeigniter アプリで奇妙な動作が見られます。
私の出力は次のようになります。
number of rows:
Warning notice
undefined variable: rows
number of rows: 10
最も奇妙なのは、PHP コードを二重に実行しようとしているように見えることですが、その理由がわかりません。どんな洞察も大歓迎です:
以下のコード:
モデル:
class foo extends CI_Controller
{
public function index()
{
$this->go();
}
public function go()
{
$this->load->model('model');
$data = array('rows'=> $this->model->count());
$this->load->view('view',$data);
}
}
モデル:
class model extends CI_Model
{
public function count()
{
$query = "Select count(1) as count from table";
$result = $this->db->query($query);
return $result->result_array();
}
}
見る:
<html>
<body>
Number of rows: <?php print_r($rows[0]['COUNT']); ?>
</body>
</html>