8 Replies - 969 Views - Last Post: 17 May 2014 - 06:51 AM Rate Topic: -----

#1 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Call to a member function read() on a non-object

Posted 17 May 2014 - 05:10 AM

I copied my site from one host to another.
That's The site
When i try to open the temporary site i get an error-

"Notice (8): Undefined property: SpacesController::$Cookie [APP/controllers/spaces_controller.php, line 68]
Fatal error: Call to a member function read() on a non-object in "/..../public_html/app/controllers/spaces_controller.php on line 68"

This is the code from line 68:

  $this->Cookie->write('mapcookiedata.longitude', '', $encrypt = false, $expires = null);
  $this->redirect(array('controller'=>'spaces','action'=>'index'));

} else {
			 
  $selected_cat_id = $this->Cookie->read('mapcookiedata.selected_cat_id');	<--- line 68
  $lower_price = $this->Cookie->read('mapcookiedata.lower_price');	



You can see few lines above it has write() which doesn't produce an error.
What is the problem here? and how can i solve it?

Is This A Good Question/Topic? 0
  • +

Replies To: Call to a member function read() on a non-object

#2 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2517
  • View blog
  • Posts: 10,086
  • Joined: 03-December 12

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 05:24 AM

I would need to see what cookie is defined to take. Currently it is in an if statement, that is not true, hence going to the else clause So, the write statement may not work either.
Was This Post Helpful? 1
  • +
  • -

#3 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:03 AM

Following @astoncipher answer i did a fast investigation and found the file controllers\app_controllers

It was like this-

<?php
  class AppController extends Controller 
  {
    public $components = array('Auth');
  }
?>



So I changed Auth to Cookie, like this-
<?php
  class AppController extends Controller 
  {
    public $components = array('Cookie');
  }
?>


Now read() is gone but allow() is the current error.
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2517
  • View blog
  • Posts: 10,086
  • Joined: 03-December 12

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:09 AM

Can't help without code! There is not allow() function in your post.
Was This Post Helpful? 0
  • +
  • -

#5 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:31 AM

Do you mean this- http://api.cakephp.o...nent.html#_read
Or this- http://api.cakephp.o...ent.html#_allow
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2517
  • View blog
  • Posts: 10,086
  • Joined: 03-December 12

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:34 AM

Neither. And api of how it is used does not show what YOU are doing.
Was This Post Helpful? 1
  • +
  • -

#7 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:43 AM

cake\libs\controller\components\auth.php
Allow() code
function allow() {
		$args = func_get_args();
		if (empty($args) || $args == array('*')) {
			$this->allowedActions = $this->_methods;
		} else {
			if (isset($args[0]) && is_array($args[0])) {
				$args = $args[0];
			}
			$this->allowedActions = array_merge($this->allowedActions, array_map('strtolower', $args));
		}
	}


Was This Post Helpful? 0
  • +
  • -

#8 ben_jamin  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 10-March 14

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:50 AM

I solved it...

<?php
  class AppController extends Controller 
  {
    public $components = array('Cookie' , 'Auth');  <--- 'Cookie' and 'Auth' 
  }
?>



thanks
Was This Post Helpful? 0
  • +
  • -

#9 astonecipher  Icon User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2517
  • View blog
  • Posts: 10,086
  • Joined: 03-December 12

Re: Call to a member function read() on a non-object

Posted 17 May 2014 - 06:51 AM

Breakdown the issue for the purpose of putting it on the forum.

What is the issue?
Post relevant code so members can assist in correcting the problem.


Is the issue IN the allow function? Is it how it is being called?
Have you initialized the appropriate variable to use the function?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1