Welcome Guest, Not a member yet? Register   Sign In
Problem Solved: Proper way to call a method from a custom library/class ?
#1

[eluser]solid9[/eluser]
Hi guys

I have loaded in the __constructor a custom class that I have created.
Now, I want to call a particular method from that class.

Let say the class name is Comments.
and it has a method called markup();

I tried calling the markup() method like this below, from the view.
Code:
foreach($comments as $c){
echo $c->markup();
}

<b>note:</b> The $comments has the same name with the Comments class.
and of course the $comments came from the controller.

the codes above works fine If I'm using PHP alone and not using CodeIgniter.
But it doesn't work when using CodeIgniter.

So what is the right codes to call a method in a custom class from the view?

Thanks in advanced.
#2

[eluser]solid9[/eluser]
I fixed the problem.
It's an object issue inside an array.

I used these codes below to fix it,
Code:
$this->data['comments'][] = new Comment($row);

Problem Solved
#3

[eluser]cPage[/eluser]
You should better use

Code:
$this->load->library('Comment');

and then use it in controller...

Code:
$this->comment->markup();





Theme © iAndrew 2016 - Forum software by © MyBB