I created my own helper on CakePHP 2.x that uses the HtmlHelper but it doesn't work, here is the code
class NavHelper extends Helper {
public $helpers = array("Html", "Javascript");
function __construct($config = array()) {
}
function link($label, $options) {
if($this->perms(array('controller'=>$options['controller'],'action'=>$options['action']))) {
$html = '<a ';
foreach($options as $label => $value) {
if($label != 'action' || $label != 'controller') {
$html .= " {$label}=\"{$value}\" ";
}
$html .= " href='".$this->Html->url(array('controller'=>$options['controller'],'action'=>$options['action']))."'>".$label."</a>";
}
return $html;
}
return '';
}
Fatal error: Call to a member function url() on a non-object in C:\Bitnami\wappstack-5.5.28-0\apache2\htdocs\pokeadmin_v2\app\View\Helper\NavHelper.php on line 17
But $this->Html->url worked perfectly on CakePHP 1.3 but on CakePHP 2.x won't work, also tried to use $this->Html = new HtmlHelper;
with the following error:
Warning (4096): Argument 1 passed to HtmlHelper::__construct() must be an instance of View, none given, called in C:\Bitnami\wappstack-5.5.28-0\apache2\htdocs\pokeadmin_v2\app\View\Helper\NavHelper.php on line 11 and defined [CORE\Cake\View\Helper\HtmlHelper.php, line 161
我也检查了文档,但没有运气。
发布于 2018-08-31 09:37:45
您打破了构造函数,有两种方式,首先它不接受其父级所需的参数(视图和配置),并且它也从不调用父级,这是初始化所需辅助映射的位置。
如果您不需要构造函数,请不要覆盖它,如果这样做,请确保接受所需的参数并将它们传递给父构造函数。
public function __construct(View $view, $settings = array()) {
parent::__construct($view, $settings);
// ...
}
发布于 2018-08-31 10:37:15
刚发现我可以使用Router :: url执行与$ this-> Html-> url相同的操作
https://stackoverflow.com/questions/-100008837
复制相似问题