Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:00:41+00:00 2026-05-25T22:00:41+00:00

I am trying to put this function ((click_add)) in library so that i can

  • 0

I am trying to put this function ((click_add)) in library so that i can call it from all the controllers. I already have get_ads() function in library. I tried various ways to shift the click_add(id) function to library and call it to view along with get_ads but doesn’t work. Please help

function __construct() {
    parent::__construct();
    $this->load->library('ads');
    $this->load->model('MGlobal');
}


public function index(){
    $data['banner']= $this->ads->get_ads();
    $this->load->view('test',$data);
}

    //i want this in library but no luck
    public function click_add($ads_id){
    $ads_site = $this->MGlobal->getAds($ads_id);
    $this->MGlobal->add_ads_view();
    redirect($ads_site['url']);
  }

//and views is like this

foreach($banner as $k=>$list){    
    echo anchor('test/click_add/'.$list['bannerid'],'<img src="'. $list['image']. '"/>');
}

please suggest me how do i achieve that with library

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:00:42+00:00Added an answer on May 25, 2026 at 10:00 pm

    It’s also important to remember the role of each part of the MVC pattern. In your click_add() method, it looks like you’re rendering a view and causing a redirect. These are two things best suited for a controller rather than a library. Rendering views and redirecting are two things that must be a controller’s responsibility, and indeed, you won’t be able to access them through the URL, which is what you’re trying to do here.

    If you want to reuse this method across multiple controllers in your site, try creating a MY_Controller core class and extending your controllers from that. That way, any methods you define in the MY_Controller will be available in any controller you subclass from.

    Without any specific error messages or a more verbose description of the problem you’re having, I’m afraid there’s little more help I can give you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to put some text inside an input, tried this: $(#someText).click(function () {
I'm trying to put this data type in a Haskell Set, but I don't
Edit: I put this snippet of code in jsbin: http://jsbin.com/eneru I am trying to
I am trying to put some distributed caching into play, I'm using this indeXus.Net
I trying to put together an Android app that will take a picture and
We're trying to put together kiosk solution where we can charge people by hour
I'm trying to put in an exception in my web.config so that one page
I'm in the backend of Wordpress, trying to create a metabox. I put this
I am trying to create a TreeView from the Silverlight TreeView control. I have
I am trying to put a click function on a php loop. But its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.