Solved

php non-object error

Posted on 2011-02-26
5
721 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 108

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 108

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
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.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now