我是一个控制器类,如图所示
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Results extends CI_Controller
{
public function index()
{
$this->load->model('my_model');
}
function validate()
{
//set validation rules here
//validate form input
if ($this->form_validation->run() == FALSE) {
// fails
$this->load->view('get_results');
}
}
function ranking1(){
$data['returned_records']= $this->my_model- >get_ranking();
$html=$this->load->view('view_ranking', $data, true);
$pdfFilePath = "ranking.pdf";
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
function top5(){
$data['returned_records']= $this->school_model->get_top5();
$html=$this->load->view('view_top5', $data, true);
//this the the PDF filename that user will get to download
$pdfFilePath = "top5.pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
}
我想从我的观点中调用这些函数:
<a href="<?php echo base_url(); ?>results/top5">Top 5</a><br>
<a href="<?php echo base_url(); ?>results/ranking1">ranking</a><br>
当我在 index()方法中调用控制器中的函数时,它们工作正常但是在上面显示的 a tag 中调用它们确实有效。
答案 0 :(得分:0)
我解决了。这是一个愚蠢的错误。我需要从控制器的构造函数中调用 my_model 来使函数访问。