Codeigniter--add “active” css class to link, how to?

后端 未结 5 2205
走了就别回头了
走了就别回头了 2021-02-09 15:02

What\'s the quickest and easiest way to add the \"active\" class to a link, so it can be styled? I\'m developing an app in CI, and I\'d like a quick easy way to do this automat

5条回答
  •  遥遥无期
    2021-02-09 15:39

    Depends on how you're outputting your link HTML.

    If you're using the URL Helper module, then you can call the anchor() function to create your links, and pass it an array of attributes as the third parameter, ie:

    $this->load->helper('url');
    echo anchor('url/path', 'Click here', array('class' => 'active'));
    

    If you're just outputting the HTML manually in your templates/views, obviously you can just create the class attribute yourself in the HTML.

提交回复
热议问题