Welcome Guest, Not a member yet? Register   Sign In
undefined function anchor()
#1

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?
" If I looks more intelligence please increase my reputation."
Reply
#2

Why do you generate url inside the Controller instead inside the View?
Best VPS Hosting : Digital Ocean
Reply
#3

(This post was last modified: 11-06-2014, 07:54 PM by InsiteFX.)

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(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.
Reply
#5

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
Reply
#6

(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.
Reply
#7

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.
Reply
#8

(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.
Reply
#9

Small question, why you use HTML helper inside the Controller ?
This is HTML building task and should be done inside your view..
Best VPS Hosting : Digital Ocean
Reply
#10

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB