Solved

php non-object error

Posted on 2011-02-26
5
725 Views
Last Modified: 2013-11-13
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
Comment
Question by:Sheils
5 Comments
 
LVL 3

Assisted Solution

by:dtocci
dtocci earned 100 total points
ID: 34990125
$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
 
LVL 4

Assisted Solution

by:LAMASE
LAMASE earned 100 total points
ID: 34991059
@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
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34991719
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
 
LVL 16

Author Comment

by:Sheils
ID: 34995158
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
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 300 total points
ID: 34998166
I find a lot of good information on SitePoint.
http://articles.sitepoint.com/article/application-development-cakephp

HTH, ~Ray
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question