Welcome Guest, Not a member yet? Register   Sign In
How call function in a view File
#1

Hey , Guys.

I have a function in Controller as follows:

Path: controllers/category.php

Code:
public function get_category_name($parent_id=NULL)
    {
       if($parent_id==0){
           return 'Parent';
       }
       else{
           $child= $this->category_m->get($parent_id);
          
           return $child->title;
       }
        
    }

Now i want access that function product display page

Path : view/products/index.php

Code:
$CI=&get_instance();

echo $CI->get_category_name($product->cat_id);
                                         

 i have tried but the above code does not work , I am using Codeigniter 3.0.6.


Please Me .

Thanks

Attached Files Thumbnail(s)
   
Reply
#2

You need to pass the variables with the desired content to the view instead of the other way around. You can have a look at the docs: http://www.codeigniter.com/user_guide/tu...pages.html
Reply
#3

You cam also create a CI helper file and add your code there then it is global to the whole app.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(06-02-2016, 03:28 AM)@InsiteFX Wrote: Thanks
Reply
#5

Additionally, if a function is only going to be used internally by your application, you don't want it to be a public method on a controller. Any public method in a controller is callable from the URL/browser unless you prefix the function name with an underscore.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB