CodeIgniter Forums

Full Version: undefined function anchor()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Fatal error: Call to undefined function anchor() in C:\xampp\htdocs\CI202-CRUD\application\controllers\welcome.php on line 13

controllers/welcome.php

PHP Code:
class Welcome extends CI_Controller {
    function 
__construct()
    {
    
//    parent::__construct();
    //    $this->load->helper(array('html','form', 'url'));
    
}
    public function 
index()
    {
        
$data = array(
            
'title' => 'Welcome Profile Edit',
            
'body' => anchor(base_url().'member_area/''Member area')
        );
        
$this->load->view('_output_html'$data);
    } 

I already autoload the helper:

autoload.php

PHP Code:
$autoload['helper'] = array('html','url','form'); 

I wonder how to fix the error?
Why do you generate url inside the Controller instead inside the View?
If you must do it from code you can do it like below. But sv3tli0 is correct it should be done in your html.

Code:
$out = '<li>' . anchor($categories[$i]['link'], $categories[$i]['title']) . '</li>';

$data = array(
    'body' => $out,
);

You cannot place php code inside php code like that, that's why the error.

@Narf: I meant inside an associated array, it just does not like it! But works fine this way.
(11-04-2014, 05:47 AM)InsiteFX Wrote: [ -> ]If you must do it from code you can do it like below. But sv3tli0 is correct it should be done in your html.

Code:
$out = '<li>' . anchor($categories[$i]['link'], $categories[$i]['title']) . '</li>';

$data = array(
    'body' => $out,
);

You cannot place php code inside php code like that, that's why the error.

Yes you can.
i have had the same experience as InsiteFX

going :

$data = array(
'body' => anchor($categories[$i]['link'], $categories[$i]['title'])
);

always seems to not work at all or throws an error. but putting it like InsiteFX stated works just fine
(11-06-2014, 07:32 PM)Hobbes Wrote: [ -> ]i have had the same experience as InsiteFX

going :

$data = array(
'body' => anchor($categories[$i]['link'], $categories[$i]['title'])
);

always seems to not work at all or throws an error. but putting it like InsiteFX stated works just fine

Nonsense.
Proof: http://3v4l.org/EfXT3

@davy_yg's issue is that he's overriding CI_Controller::__construct(), but not calling parent::__construct() in the override. The constructor is what triggers the autoloader.
If using base_url(), I find it much easier to place the additional URL path inside the () or the function.

base_url('path/to/item')

rather than spread it out, makes the code easier too.
(11-06-2014, 11:22 PM)Narf Wrote: [ -> ]
(11-06-2014, 07:32 PM)Hobbes Wrote: [ -> ]i have had the same experience as InsiteFX

going :

$data = array(
'body' => anchor($categories[$i]['link'], $categories[$i]['title'])
);

always seems to not work at all or throws an error. but putting it like InsiteFX stated works just fine

Nonsense.
Proof: http://3v4l.org/EfXT3

@davy_yg's issue is that he's overriding CI_Controller::__construct(), but not calling parent::__construct() in the override. The constructor is what triggers the autoloader.

In full agreement, you must uncomment the call to the controllers parent.
Small question, why you use HTML helper inside the Controller ?
This is HTML building task and should be done inside your view..
i was just sayin' that when I use any of the html helper functions, I half to put them in a variable before putting them into an array or else like I said, it either does not work or throws an error.
Pages: 1 2