I building my first cake PHP application, all things configured correctly, but when i calling to model on controller as below it gives an error message when i browse this url on localhost

class NotesController extends AppController{
var $name = "Notes";

function index(){
    $this->set('notes',$this->Note->find('all'));
}
}

this gives an error like this. Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in D:\wamp\www\cakephp\app\Model\note.php on line 4

my model file has follow codes

class Note extends AppModel{
  $name = "Note";
}

i think db connection and other configurations are ok,please any one can help me, i ll highly appreciated you. thanks lot....

share|improve this question

2 Answers

up vote 2 down vote accepted

Change:

$name = "Note";

To:

var $name = "Note";

or:

public $name = "Note";

CakePHP recommends using var to keep code compatible with PHP4. However, this is completely unnecessary and it's better to use public.

That being said, the code you posted should not give an unexpected T_STRING error but, rather, an unexpected T_VARIABLE error. So there may be something else going on as well.

share|improve this answer
great thanks for help, i using 5.3.8 so i use variable name with public..thanks again – Suneth Feb 7 '12 at 17:24
You're very welcome. – webbiedave Feb 7 '12 at 17:34
if you are using cake2, throw it away completely. totally unnecessary (only needed in cake1.x for PHP4). – mark Feb 7 '12 at 19:37
Mark, why would you remove the visibility scope from php5 code...? – burzum Feb 8 '12 at 11:58
He means to throw away the use of var and to just use the PHP5 access modifiers instead. – webbiedave Feb 8 '12 at 16:48

It has to be

var $name = "Note";

but that's php4, you want php5+

public $name = "Note";

when there are errors like this I suggest you to google them first. They're really easy to find and resolve. Also you might want to read about OOP first because it does not look like you have experience with it -> http://php.net/manual/en/language.oop5.php

share|improve this answer
great thanks for help, i using 5.3.8 so i use variable name with public..thanks again – Suneth Feb 7 '12 at 17:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.