1
我对CI和GC相当陌生,所以我的问题可能只是语法问题。我试图在管理员更新记录后发送电子邮件给记录的所有者。关于插入的电子邮件给管理员,但是在更新时给用户的电子邮件什么也不做。更新后的Grocery Crud回调不发送电子邮件
电子邮件功能控制器:
public function email_admin_vehicle()
{
$this->load->library('email');
$this->email->from('[email protected]', 'Admin');
$this->email->to('[email protected]');
$this->email->subject('New Vehicle Added');
$this->email->message('A new vehicle has been registered. Please log in to your admin panel to approve the vehicle.');
$this->email->send();
echo $this->email->print_debugger();
}
public function email_user_vehicle($post_array)
{
$this->load->library('email');
$this->email->from('[email protected]', 'Cars in the Park');
$this->email->to($post_array['email']);
$this->email->subject('Vehicle Updated');
$this->email->message('An administrator has updated your vehicle details. Please log on to your account to view the changes.');
$this->email->send();
echo $this->email->print_debugger();
}
回调和CG功能:
//==================\\
//START: Vehicle Crud
//==================\\
public function vehicle()
{
if (!$this->ion_auth->logged_in())
{
redirect('auth/login');
}
else {
if (!$this->ion_auth->is_admin()) {
// Get User_id if standard user
$user = $this->ion_auth->user()->row();
// Build Crud
$crud = new grocery_CRUD();
$crud->unset_jquery();
// Timestamps
$crud->set_model('MY_grocery_Model');
// Table
$crud->set_table('vehicle');
// Special Queries
$crud->where('vehicle.user_id', $user->id);
// Display Rules
$crud->display_as('registration','Licence Plate');
$crud->display_as('user_id','Name');
$crud->display_as('event_id','Event');
$crud->display_as('stand_id','Stand');
$crud->display_as('club_id','Club');
// Relations
$crud->set_relation('event_id','event','event_name');
$crud->set_relation('user_id','users','username');
$crud->set_relation('club_id','club','club_name');
$crud->set_relation('stand_id','stand','code');
// Validation
$crud->set_rules('year','Year','integer');
$crud->required_fields('make','model','year','country','registration','event','club');
// Fields Rules
$crud->unset_add_fields('created','updated','stand_id','verified','paid','user_id','ref_number');
$crud->unset_edit_fields('created','updated','stand_id','verified','paid','user_id','ref_number');
$crud->unset_columns('user_id','created','updated','verified','paid');
$crud->unset_export();
$crud->unset_print();
// Adding Buttons
$crud->add_action('Print', '', 'print/single','ui-icon-print');
// Callbacks
$crud->callback_after_update(array($this, 'email_user_vehicle'));
// Render
$output = $crud->render();
$this->_cruds_output($output);
}
else {
$crud = new grocery_CRUD();
$crud->unset_jquery();
// Timestamps
$crud->set_model('MY_grocery_Model');
// Table
$crud->set_table('vehicle');
// Special Queries
// Display Rules
$crud->display_as('registration','Licence Plate');
$crud->display_as('user_id','Name');
$crud->display_as('event_id','Event');
$crud->display_as('stand_id','Stand');
$crud->display_as('club_id','Club');
// Relations
$crud->set_relation('event_id','event','event_name');
$crud->set_relation('user_id','users','username');
$crud->set_relation('club_id','club','club_name');
$crud->set_relation('stand_id','stand','code');
// Adding Buttons
$crud->add_action('Print', base_url().'/assets/img/print.png', 'printforms/single','');
// Unset Fields
$crud->unset_add_fields('created','updated','user_id','ref_number');
$crud->unset_edit_fields('created','updated','user_id','ref_number');
// Callbacks
//$crud->callback_after_insert(array($this, 'add_new_club_user'));
$crud->callback_after_insert(array($this, 'email_admin_vehicle'));
//$crud->callback_after_update(array($this, 'email_user_vehicle'));
// Render
$output = $crud->render();
$this->_cruds_output($output);
}
}
}
正如我说,这可能只是我不知道我在做什么可言,但任何帮助,将不胜感激。
'$ crud-> callback_after_update(阵列($此, 'email_user_vehicle'));'和'$ crud-> callback_after_insert(阵列($此,“email_admin_vehicle '));'在哪里交换。该代码与交换的2条语句一样工作。 – 2015-02-23 13:25:48