CodeIgniter Forums
Beginner: Use anchor in controller! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Beginner: Use anchor in controller! (/thread-25194.html)

Pages: 1 2


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]WebbHelp[/eluser]
Hi!

If I write code in my view file then I can write anchor('dir/file','press here');
But if I am in my controller file, how can I write to reach the anchor function? I can't write anchor('dir/file','press here'); in my controller file, that doesn't work, how do I write in that file?

Thanks //WebbHelp


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]WebbHelp[/eluser]
Hey!

Sorry, it works with only anchor();!
I thought that I had load the class for it, but it was the URI class, What is the different, I would be great to know how to seperate them, I mean, I almost guess if I will load URI or URL class!


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]jedd[/eluser]
Like the doctor who, when asked by his patient what to do about the pain when he does this, advises the patient to not do that any more .. I can advise you to not put anchor()s in your controller.


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]WebbHelp[/eluser]
You mean like echo it out, I put the anchor in my controller, in a array like this:

$data['link'] = anchor('dir/file/function', 'Just press and go');

Is that a bad thing to use it, I mean when I do it in that way?


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]überfuzz[/eluser]
It's very common to use a structure called mvc while setting up a CI site. For starter, use the view files to display stuff in the browser. You know stuff like links, pictures, text, and what have you.


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]WebbHelp[/eluser]
Ok, so I should put my links in the view file!
Thanks, it is thins like this I want to know, specially now when I am a beginner on codeigniter!

Hey, one more question:

When I wrote clean PHP code, I almost started like this.

I got my design on one page, and then I got other files with the content, I mean like this:

HTML CODE:

<div id="header">

<div id="content">

if($_GET['p'] == 'start')
{
include('start.php');
}
if($_GET['p'] == 'contact')
{
include('contact.php');
}

</div>

</div>

END HTML CODE:

You see I only got the layout code in one page and then I included the page which will shows.
How should I do in codeigniter, can I do something like this and only got the layout code in one file.
I am looking for a good solution for this!

Thank you //WebbHelp


Beginner: Use anchor in controller! - El Forum - 12-03-2009

[eluser]jedd[/eluser]
[quote author="webbhelp" date="1259899688"]
Ok, so I should put my links in the view file!
[/quote]

HTML, as a rule, goes into the view file.

Quote:Thanks, it is thins like this I want to know, specially now when I am a beginner on codeigniter!

Read through the wikipedia article on MVC, and any other tutorials you can find out there on the Intergoogle.

Also read through the general sections in the CI user guide.

Quote:You see I only got the layout code in one page and then I included the page which will shows.
How should I do in codeigniter, can I do something like this and only got the layout code in one file.
I am looking for a good solution for this!

Have a read of [url="/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]this wiki article[/url] for one way of doing this. It's mostly about MY_Controller (but that will likely be your next question anyway) but covers the whole 'generate a view partial' thing that you're talking about.

There are lots of threads - [url="/forums/viewthread/110969/"]this one kind of spawned the above wiki page[/url], for example - just search on 'header footer' and you'll stumble across most of them.

You should probably read through the [url="/wiki/FAQ"]FAQ[/url] too, so you don't ask questions that are already answered.


Beginner: Use anchor in controller! - El Forum - 12-04-2009

[eluser]WebbHelp[/eluser]
Ok, I think I like that idé:

$this->load->view('header');
$this->load->view('content');
$this->load->view('footer');

Is there any other solution to, that I should know about?

And, i got a problem, or not a problem but when I include my CSS, file, how should I link it, to get the right href/adress without writing the whole path ex: http://www.webbhelp.se/....

Thanks Smile


Beginner: Use anchor in controller! - El Forum - 12-04-2009

[eluser]jedd[/eluser]
[quote author="webbhelp" date="1259964567"]
And, i got a problem, or not a problem but when I include my CSS, file, how should I link it, to get the right href/adress without writing the whole path ex: http://www.webbhelp.se/....
[/quote]

If you look at the view file that I posted in [url="/forums/viewthread/110969/#559962"]this message[/url] you'll see how I've used link_tag()


Beginner: Use anchor in controller! - El Forum - 12-04-2009

[eluser]WebbHelp[/eluser]
Thanks, but where is the path link_tag(); refere to?
I mean, what directory shall I put my CSS - stylesheet file in?

And is that a helper? if, which helper, I mean I want to read the documentation and find out other path helpers.

Thanks a lot for helping me Smile