0

Error: Call to a member function create() on a non-object in cakephp. I have already defined all of these in my controller page.

ContactsController:

<?php
 public $helpers = array('Html', 'Form');
 public $components = array('RequestHandler');
 public $uses = array("Contact");

 public function index(){
  if ($this->RequestHandler->isPost()) {
    $this->Contact->set($this->data);
    //validates here
  }
?>

index.ctp

<?php
//form
echo $form->create("Contact");
echo $form->inputs();
echo $form->end('Send');
?>

But am I still getting the fatal error. need help thanks.

leeshin
  • 1,043
  • 5
  • 15
  • 30

2 Answers2

4

Use $this->Form->create() instead of $form->create().

You must use $this before helper object.

Your index.php code should looks like:

<?php
//form
echo $this->Form->create("Contact");
echo $this->Form->inputs();
echo $this->Form->end('Send');
?>
Arun Jain
  • 5,476
  • 2
  • 31
  • 52
  • yeah, did that, i forgot for a bit. but why am i getting this error again?Call to a member function send() on a non-object. is this because I am using cakephp.2? – leeshin Jul 04 '13 at 05:16
  • Check the book.cakephp.org how to work with the new CakeMail class in cake2 and the most important read the migration guide where all the changes are listed. – floriank Jul 04 '13 at 08:59
0

Check your controller classes well. Did you redefine AppController::render() or reimplement it in a subclass? You might have done so to specify a layout for your application. I was getting the same error. And I discovered that the $view argument(which is the name of the view to be rendered) that goes into the render method was null because I overrode the render method. If you didn't overrride render(), check for anywhere you might have set the $view property of the controller.

oyelaking
  • 444
  • 5
  • 7