CodeIgniter Forums
Problem using anchor tag (solved) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem using anchor tag (solved) (/showthread.php?tid=23930)

Pages: 1 2 3


Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]stormlead[/eluser]
hi1
i just got my first problem solved and was into new one again, Now i got the css linked and to move further i just wanted to link to a new page.
for which i wrote
Code:
<?php echo anchor('system/application/views/welcome_message.php','click here');?>
But i get a an error saying call to undefined function.
Can any one tell me how to properly link a document.


Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]rogierb[/eluser]
you can only link to a controller. Not to a view file

Code:
<?php echo anchor('my_controller/my_method/var_1','click here');?>



Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]stormlead[/eluser]
@rogier
ok i got it we can't linka view, but still my problem is the error
anchor function undefined.
i.e.
But i get a an error saying call to undefined function.


Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]stormlead[/eluser]
Also now if i remove the anchor function and write as below
Code:
<a href="system/application/controllers/next.php" style="text-decoration:none;" class="style1"> click here</a>
when a click on the link i get the error
Fatal error: Class 'Controller' not found in C:\wamp\www\CodeIgniter_1.7.2\system\application\controllers\next.php on line 3
the code for my controller next is
Code:
&lt;?php
class Next extends Controller {
function Next()
{
     parent::Controller();    
}
    
function index()
{
    $this->load->view('welcome_message');
    }

}



Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]BrianDHall[/eluser]
Code:
<a href="/next" style="text-decoration:none;" class="style1"> click here</a>



Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]BrianDHall[/eluser]
Oh duh, silly me - I just reread and found your problem. anchor() is an optional helper, you must load it if you want to use it:

http://www.codeignitor.com/user_guide/helpers/url_helper.html


Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]stormlead[/eluser]
@Brian
i did not understand where we have to load the url helper.
and i am really not getting how to link a page. Please help through this following are the codes which i am writting
welcome.php
Code:
&lt;?php

class Welcome extends Controller {
var $base;
var $css;

function Welcome()
{
     parent::Controller();    
}
    
function index()
{
    $this->load->helper('url');
     $base=$this->config->item('base_url');
     $css=$this->config->item('css');
    $data['css']=$this->css;
    $data['base']=$this->base;
    $data['mytitle']='Welcome to my first page';  
     $data['mytext']='Ok! So i am getting a hang of CI. Its good lets just move on...';  
    $this->load->view('index',$data);
    }

}
code for index.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;This is test page&lt;/title&gt;
&lt;base href="&lt;?php echo "$base"; ?&gt;" /&gt;
&lt;link rel="stylesheet" type="text/css" href="css/mystyle.css" /&gt;
&lt;body bgcolor="#CCCCCC"&gt;
<div align="center" class="style1" >
This is my test page </div><br />
<div align="center" class="style2" >
&lt;?php echo "$mytitle";?&gt;
</div><br />
<div align="center" class="style3" >
&lt;?php
echo "$mytext";
?&gt;
</div>
<br />
<div align="center" style="text-decoration:none;" class="style3" >
&lt;?php
echo  anchor('system/application/controllers/next.php','click here');
?&gt;
</div>

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

and in controller for next.php
the code is

Code:
&lt;?php

class Next extends Controller {
function Next()
{
     parent::Controller();    
}
    
function index()
{
    $this->load->view('welcome_message');
    }

}



Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]stormlead[/eluser]
i have loaded the helper and the anchor is working but now
anchor returns this url
http://localhost/CodeIgniter_1.7.2/index.php/system/application/controllers/next

which give 404 error.
i want to link the click here to welcome_message.php which is in views .
Please help me for doing this.


Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]stormlead[/eluser]
P


Problem using anchor tag (solved) - El Forum - 10-26-2009

[eluser]jedd[/eluser]
Show the anchor line.

(I think this has already been covered.)