Reputation:
Fatal error:
Call to a member function charset() on a non-object in D:\xampp\htdocs\demo\app\controllers\test_controller.php on line 10
PHP Controller Code:
<?php
class TestsController extends AppController
{
var $name="Tests";
var $helpers = array('Html');
var $uses=array();
# demo action to check wheather html helper is working or not
function index()
{ echo "111111111";
echo $this->Html->charset();
echo "22222222222";
}
}
?>
I am getting the above error while hitting the url: http://localhost/demo/tests
I am using CakePHP 2.0 ALPHA (latest version).
Please let me know what is the root cause.
Upvotes: 0
Views: 1854
Reputation: 11212
Following CakePHP's MVC convention, you should by using behaviors in models, components in controllers and helpers in views. You are currently trying to use a helper in a controller, which won't work. I suggest you go back and have another look at the documentation, but for something like HtmlHelper::charset()
you really want to be calling that once in the <head>
tag of your layout (which is also part of the view layer):
Upvotes: 2