所以我有一个控制器来显示站点布局,然后我有另一个控制器来管理电子邮件。我的问题是如何将它们组合到同一个页面(相同的视图)我只是将我的电子邮件控制器的功能添加到我的站点控制器?那么该站点控制器具有 send() 方法,然后将所有内容从我的“新闻通讯”视图移动到我的“主页”视图中?
现场控制器
<?php
class Site extends CI_Controller
{
function index()
{
$this->load->model('site_model');
$data['records']= $this->site_model->getAll();
$this->load->view('home',$data);
}
}
?>
电子邮件控制器
class Email extends CI_Controller{
function index()
{
$this->load->view('newsletter');
}
function send()
{
$this->load->library('form_validation');
//field name, error message, validaion rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('name', 'Email Address', 'required');
if($this->form_validation->run()==FALSE)
{
$this->load->view('newsletter');
}
else
{
$name = $this->input->post('name');
$email = $this->input->post('email');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('', '');
$this->email->to($email);
$this->email->subject('This is an email test');
$this->email->message('Sucess');
$path = $this->config->item('server_root');
$file = $path .'CodeTest/attachments/newsletter1.txt';
$this->email->attach($file);
if($this->email->send())
{
echo ' Your email has been sent.';
}
else {
show_error($this->email->print_debugger());
}
}
}
}