Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to undefined function anchor()
#1

[eluser]Master276[/eluser]
Hi Guys,
i'm a newbie and i've got a problem with the anchor function that doesn't work

here is my code

The controller
Code:
<?php
class Blog extends CI_Controller {

public function __Blog(){
  parent::__Blog();
  $this->load->helper('url');
  $this->load->helper('form');
  
}


function index()
{
  $data['title'] = "My Blog Title";
  $data['heading'] = "My Blog Heading";
  $data['query'] = $this->db->get('entries');
  
  $this->load->view('blog_view', $data);
}
}
?>

The view
Code:
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1>&lt;?=$heading?&gt;</h1>


&lt;?php foreach($query->result() as $row): ?&gt;

<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->body?&gt;</p>

&lt;?php echo anchor('blog/comments','Comments','title="Nuovo commento"');?&gt;

<hr>

&lt;?php endforeach; ?&gt;


&lt;/body&gt;
&lt;/html&gt;

do you find any errors?

Thank you

Lorenzo
#2

[eluser]jojo777[/eluser]
Looks like you've loaded the helper, good!

Code:
$this->load->helper('url');

I've just copied the anchor code line in one view I'm working on and the link is created properly.

Strange...
#3

[eluser]Master276[/eluser]
In which folder do you have the helpers?
#4

[eluser]jojo777[/eluser]
Autoload.php

Code:
$autoload['helper'] = array('url');
#5

[eluser]Master276[/eluser]
It seems that the system didn't find the helpers. I've copied them in both application/helpers and system/helpers folders. I've to set a path?
#6

[eluser]jojo777[/eluser]
I've never copied helpers in other folder, they are always in system/helpers/

Dis you try a small example? loading a view with a simple anchor!?
#7

[eluser]Master276[/eluser]
Just tried...the browser give me the same error.

Fatal error: Call to undefined function anchor() in C:\xampp\htdocs\codeigniter\application\views\blog_view.php on line 14
#8

[eluser]Master276[/eluser]
I solved replacing
Code:
public function __Blog(){
  parent::__Blog();
  
  $this->load->helper('form');
  $this->load->helper('url');
  
  
}

with

Code:
public function __construct(){
  parent::__construct();
  
  $this->load->helper('form');
  $this->load->helper('url');
  
  
}

Someone can explain me the why?
#9

[eluser]jojo777[/eluser]
Sorry i didnt realize about the constructor.

Thats the correct way. Is not like Java. Is a built in function.




Theme © iAndrew 2016 - Forum software by © MyBB