Possible Duplicate:
Call to a member function on a non-object
What is wrong with this line of code?
$this->Post->saveField('slug', $this->Text->truncate(Inflector::slug($post['Post']['title']),25,array('exact'=>false,'html'=>false,'ending'=>'')));
As it gives me the error: Fatal error: Call to a member function truncate() on a non-object in /nfs/c03/h01/mnt/12345/domains/jazz.com/html/app/Controller/PostsController.php on line 161
Should I be using something else? Like $this->request->data['title'];
The error means that
$this->Textis not an object, and you can’t call thetruncate(or any other) method on it.Is
Textsupposed to be a model? If you want to use several models in a controller you can add it to theusesarray:If it’s a component, you should add it to the
componentsarray.You can use the
Stringclass if you are looking for thetruncatemethod that TextHelper provides. See the example given forString::truncatehere: http://book.cakephp.org/2.0/en/core-utility-libraries/string.html