Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP Time Helper Problem
    primarykey
    data
    text
    <p>I think I might be making a mistake here. I am getting the following error when trying to use a simple function in the time helper in my controller. I don't get an error when using the same function call in the view.</p> <p>Below is the error from the controller. Followed by the controller code that is failing. Followed by the view code that is working.</p> <p>Any help is appreciated!</p> <p><strong>Error:</strong></p> <p><em>Notice (8): Undefined variable: time [APP/controllers/temp_users_controller.php, line 25] Code $checkTime = $time->gmt(); Fatal error: Call to a member function gmt() on a non-object in /var/www/studydeck/app/controllers/temp_users_controller.php on line 25</em></p> <p><strong>Controller:</strong></p> <p>class TempUsersController extends AppController {</p> <pre><code>var $name = 'TempUsers'; var $scaffold; var $components = array('Auth'); var $helpers = array('Time'); function beforeFilter() { //list of actions that do not need authentication $this-&gt;Auth-&gt;allow('userCleanUp'); } //this function will delete TempUser accounts which have not been activated function userCleanUp() { $checkTime = $time-&gt;gmt(); $this-&gt;set('checkTime',$checkTime); } </code></pre> <p>}</p> <p><strong>View:</strong></p> <p>echo $time->gmt();</p> <p>Update: I tried $time = new TimeHelper(); I received the error Fatal error: Class 'TimeHelper' not found in /var/www/studydeck/app/controllers/temp_users_controller.php on line 23</p> <p>I do have var $helpers = array('Time')</p> <p>Also not that echo $time->gmt(); works in the view with out instantiating time anywhere.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload