• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 774
  • Last Modified:

php non-object error

I am trying to create a php application in cakephp using the stp by step instruction provided on this website:
http://www.packtpub.com/article/create-a-quick-application-in-cakephp-1

When I try to run add.ctp I get the following error


Notice (8): Undefined variable: form [APP/views/tasks/add.ctp, line 1]
Code | Context
<?php echo $form->create('Task');?>
$___viewFn      =      "/home/wowisla1/public_html/cake/cakephp/app/views/tasks/add.ctp"
$___dataForView      =      array()
include - APP/views/tasks/add.ctp, line 1
View::_render() - CORE/cake/libs/view/view.php, line 647
View::render() - CORE/cake/libs/view/view.php, line 390
Controller::render() - CORE/cake/libs/controller/controller.php, line 848
Dispatcher::_invoke() - CORE/cake/libs/dispatcher.php, line 174
Dispatcher::dispatch() - CORE/cake/libs/dispatcher.php, line 119
[main] - APP/webroot/index.php, line 78

Fatal error: Call to a member function create() on a non-object in /home/wowisla1/public_html/cake/cakephp/app/views/tasks/add.ctp on line 1


the code in add.ctp is as follows
 
<?php echo $form->create('Task');?>
<fieldset>
<legend>Add New Task</legend>

<?php
echo $form->input('title');
echo $form->input('done');
?>

</fieldset>
<?php echo $form->end('Add Task');?>

<?php echo $html->link('List All Tasks', array('action'=>'index')); ?>

Open in new window



I has done some research and I believe that the error is because $form is not an object or not set. But I can't figure out how to set it.
0
Sheils
Asked:
Sheils
3 Solutions
 
dtocciCommented:
$form needs to be instantiated first before you can call methods.  The code would look something like this:

$form = new Form();

The above assumes the class name is "Form" and that it takes no parameters. You'll have to figure out the real class name and what parameters you need to pass in.
0
 
LAMASECommented:
@dtocci in cakephp "$form" should be an helper.

Sure you have installed cakephp correctly? Ere you calling it directly and not through a route?
http://webexpose.org/2007/05/09/cakephp-routes/
0
 
Ray PaseurCommented:
Looking at the packtpub article, I am a little surprised that the article never mentions instantiation of the class that creates the $form object.  It's also a little behind the times in its variable terminology.  For example, it uses the old-style variable declaration var instead of current terminology that declares the variable scope such as public, private, protected.  You might want to look for more current examples.
0
 
SheilsAuthor Commented:
Ray

Can you suggest a website where I can find some good recent tutorials

Lamase,

I created a subdomain called cake to play around with.
Then I up loaded cakephp-2.0.0-dev-0-gbe96338.zip to the root folder of the subdomain. Then extracted it in a folder called cakephp which is inside the domain root folder.
Then create the database and the table from the packpub website.
Then change security.salt and security.cipherSeed.  in config/core.php
Also added App::import('Core', 'Debugger') to bootstrap.php

0
 
Ray PaseurCommented:
I find a lot of good information on SitePoint.
http://articles.sitepoint.com/article/application-development-cakephp

HTH, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now