How to create a function from this one line code? |
[eluser]term25[/eluser]
I have a menu in my view: !!! THE CODE BELLOW IS MESSED UP !!! The if conditions are deleted even when used in code. On stackoverflow it is displayed correctly: http://stackoverflow.com/questions/11040...-line-code Code: <ul> And I am sending to this view a variable $nav_item from my controller e.g. news (I have controllers for every item in the navigation so: news, products and media controller) like this: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); So, it is woking good, but the code in a link is really long: Code: <a href="<?php echo base_url(); ?>news"class="active-nav-item">News</a> I would like to make a function from this where I send only two parameters and it will do other things automatic. E.g. it could look like this: <a href="<?php echo base_url(); ?>news"class="active-nav-item">News about Cars</a> So, if $navitem == 'news' it echoes "class='active-nav-item'" How to do this function so I can put it in my e.g. myown_helper.php in helpers folder. Thanks in advance.
[eluser]nagata[/eluser]
teh function Code: function is_active_item($item,$this) { Code: <a >myown->is_active_item('news',$navitem); anyways simply use the function like $this->myown->is_active_item('news',$navitem);
|
Welcome Guest, Not a member yet? Register Sign In |