简体   繁体   中英

Html Helper CakePHP

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.

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):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM