Tuesday, 27 August 2013

How to create UDF (User Defined Fuction) in CakePHP

How to create UDF (User Defined Fuction) in CakePHP

i have a function like this:
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;
}
?>
i want to use the function in App::Model...
i create like this, but it's not work
<?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;
}
}
?>

No comments:

Post a Comment