Welcome Guest, Not a member yet? Register   Sign In
Error with Html Helper
#1

[eluser]mrahsanahmad[/eluser]
Sorry to bring my own problem, I couldnt create a new post

Hello

I cant call myself a master of CodeIgniter but there is one problem I cannot make out of.
I am using module to generate navigation bar automatically.

//in autoload.php
Code:
$autoload['libraries'] = array(template,Navbar);

**Navbar is a library (module) in application/library/Navbar.php ***
//Navbar.php

Code:
class Navbar {
private $CI = "";
var $navbar = 'ITPL';

public function Navbar(){
$this->CI =& get_instance();
$this->CI->load->helper('html');
$this->CI->load->helper('date');
$this->disp_navbar();  
}

public function disp_navbar(){
  $this->gen_navbar();
  $this->CI->template->write('navbar',$this->navbar);
}

public function gen_navbar(){
  $this->navbar = now();
}

}


Every thing works fine. However if I change now() (function of date helper) in the last line to :

Code:
anchor(some address,some string);

which is a function of html helper, I get error Call to undefined function anchor()
Code:
$this->CI->html->anchor(some address,some string)
, I get error Call to a member function anchor() on a non-object
Code:
$this->CI->date->now
, I get error Call to a member function now() on a non-object

I have been trying to solve this for hours now. First, I dont understand why should now() function work without the following prefix
Code:
$this->CI->date

to use any library function, I always use the following and this always works
Code:
$this->CI->load->library(myLibrary);
$this->CI->myLibrary->myFunction();

Qs1. Why does helper function such as now() (from date helper) does not require a prefix
Qs2. Assuming that helper functions do not require a prefix, why does this fails in the case of html...

Please guide me so I can move on Smile



#2

[eluser]InsiteFX[/eluser]
anchor is not a method in the html helper it is a method in the url helper!
Code:
anchor(some address,some string);

Wrong!
Code:
class Navbar {
private $CI = "";
var $navbar = 'ITPL';

public function __construct(){  // <-----
$this->CI =& get_instance();
$this->CI->load->helper('html');
$this->CI->load->helper('date');
$this->disp_navbar();  
}

Also read the User Guide to see what now() really does!

public function disp_navbar(){
  $this->gen_navbar();
  $this->CI->template->write('navbar',$this->navbar);
}

public function gen_navbar(){
  $this->navbar = now();
}

}




Theme © iAndrew 2016 - Forum software by © MyBB