我有这样的功能:
func_seo.php
<?php
function seo_title($s) {
$c = array (' ');
$d = array ('-','/','\\',',','.','#',':',';','\'','"','[',']','{','}',')','(','|','`','~','!','@','%','$','^','&','*','=','?','+');
$s = str_replace($d, '', $s);
$s = strtolower(str_replace($c, '-', $s));
return $s;
}
?>
我想在 App::Model 中使用该功能。
我这样创建,但它不起作用:
<?php
class MyModel extends AppModel{
var $name = 'MyModel';
public function beforeSave(){
$this->element('func_seo'); //Function Element View/Elements/func_seo.php
$this->data['MyModel']['name_seo'] = seo_title($this->data['MyModel']['tutorial_name']);
return true;
}
}
?>