CodeIgniter Forums
Links and IDs - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Links and IDs (/thread-33875.html)



Links and IDs - El Forum - 09-11-2010

[eluser]csabessz47[/eluser]
Hy all!

I'm fairly newbie to Codeigniter but I like it already.

I would like to create links (yes I used anchor() already), but I need something like this:

Code:
<a href="..." id="XX">YYY</a>

So I've trouble with the id parameter. How could I create it?

My code now:
Code:
&lt;?php foreach($menu as $key=>$item): ?&gt;
  <li>&lt;?=anchor($link[$key],$item); ?&gt;</li>
&lt;?php endforeach; ?&gt;

I have 2 arrays:
Code:
$data["menu"] = array("Main","About me","References","Services","Contact");
$data["link"] = array("","cv","refer","service","contact");

And I managed to create this:
Code:
<li><a href="http://localhost/cs/index.php/cv">About me</a></li>

But I need for example: id="cv"

How can I create it?


Links and IDs - El Forum - 09-11-2010

[eluser]CroNiX[/eluser]
Code:
anchor($url, $title, $attributes);

anchor('cv', 'About Me', 'id="cv"');
would produce (assuming base_url is set to 'http://localhost/cs/index.php/'):
Code:
<a href="http://localhost/cs/index.php/cv" id="cv">About Me</a>

Code:
anchor('cv', 'About Me', 'id="cv" class="someclass"');

would produce:
Code:
<a href="http://localhost/cs/index.php/cv" id="cv" class="someclass">About Me</a>



Links and IDs - El Forum - 09-11-2010

[eluser]csabessz47[/eluser]
Thank you for the answer!

I didn't think it was easy like this Smile


Links and IDs - El Forum - 09-11-2010

[eluser]CroNiX[/eluser]
No prob. This would convert your arrays the way you want.

Code:
$data["menu"] = array("Main","About me","References","Services","Contact");
$data["link"] = array("","cv","refer","service","contact");

foreach($data["menu"] as $k => $item)
{
    echo anchor($data['link'][$k], $item, 'id="' . $data['link'][$k] . '"') . '<br />';
}



Links and IDs - El Forum - 09-11-2010

[eluser]csabessz47[/eluser]
yes i used the same way Wink thanks

and again: i'm a newbie:

in the controller i have 2 functions: index, and cv.

I'd like to link a CSS file, its in localhost/cs/css/style.css
How can I solve this?

in the controller:
Code:
$data["css"] = "../../css/style.css";
in the view file:
Code:
&lt;link href="&lt;?=$css?&gt;" rel="stylesheet" type="text/css" /&gt;

this works at the following url:
Quote:http://localhost/cs/index.php/blog/cv
and
Quote:http://localhost/cs/index.php/blog/
but if i just type
Quote:http://localhost/cs
it doesn't work.

Any ideas or how should I solve this? I haven't find any tutorial or description for this.


Links and IDs - El Forum - 09-11-2010

[eluser]CroNiX[/eluser]
Use an asset manager, like caribiner: http://codeigniter.com/wiki/Carabiner/

Then you have a header view that gets called on every page load. From the controller you can dynamically assign css/js whatever to the head of your document in the header view.


Links and IDs - El Forum - 09-14-2010

[eluser]csabessz47[/eluser]
I need help again.
I downloaded Carabiner, copied the config and library files, but I can't make it work.
My css folder is next to the 'system' folder.
My controller:
Code:
function Main() {
    parent::Controller();
    $this->load->helper('url');
    $this->load->library('carabiner');
    
    $carabiner_config = array(
        'script_dir' => 'assets/scripts/',
        'style_dir'  => 'css/',
        'cache_dir'  => 'assets/cache/',
        'base_uri'   => base_url(),
        'combine'    => TRUE,
        'dev'        => FALSE
    );
    $this->carabiner->config($carabiner_config);
    $this->carabiner->css('style.css');
}

The problem is that I can't use it. I read the wiki but I don't understand.
Should I use
Code:
$this->carabiner->display('css')
but if yes: where?


Links and IDs - El Forum - 09-15-2010

[eluser]csabessz47[/eluser]
okey i solved:

in the controller:
Code:
$data["css"] = base_url()."css/style.css";

in the view:
Code:
&lt;link rel="stylesheet" type="text/css" href="&lt;?=$css?&gt;" media="screen" /&gt;

But i didn't want to use full url.