首先转到http://pkg.io/并获取您的基本扩展名文件。
如果输入不干净的单词,您可能会想要使用'safecracker_submit_entry_start'钩子来引发错误。扩展的最重要的部分是注册你想使用的方法和钩子,否则没有代码会运行。
您的代码应该是这个样子:
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$data = array(
'class' => __CLASS__,
'method' => 'clean', // point to the method that should run
'hook' => 'safecracker_submit_entry_end', // point to the hook you want to use to trigger the above method.
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
}
一旦方法被调用,你就可以开始你的清洁。在定义它时,确保将safecracker对象传递给干净的方法。例如:
public function clean($sc){
print_r($sc);
}
谢谢@philip。这真的很有帮助。感谢您的链接。我唯一的问题是我如何告诉clean函数清理$ _POST ['title'],因为我想清除提交的条目的标题。在干净的功能里面我应该有一些像$ _POST ['title'] = clean($ _ POST ['title']);.我希望标题在发送到数据库之前进行清理。 – Pinkie 2012-03-21 02:39:46
您可以在挂钩调用的方法内部执行此操作。你想要它真的清洁它吗?或拒绝某些关键字的标题? – 2012-03-21 16:57:04
您可能还在寻找:$ this-> EE-> output-> show_user_error(“FooBar”) – 2012-03-21 17:00:29