Welcome Guest, Not a member yet? Register   Sign In
Create custom library
#1

[eluser]Tommy Liu[/eluser]
Dear experts - I have no idea that why I cannot call the function that I stored in my custom library called "Udpwebdb.php".

If I remove quota lines in function as below. I can show the result correctly. Please give me some hints to me to fix the problem. Thank you.

Quote: $this->load->library('udpwebdb');
printf('%s',this->updwebdb->tabletojson());

Code:
public function myctrlresult()
{
$this->load->library('udpwebdb');
printf('%s',this->updwebdb->tabletojson());
printf('%s','here');
}



File fullname: ../library/Udpwebdb.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Udpwebdb {

    public function tabletojson()
    {
     return 'hello';
    }
}
#2

[eluser]TheFuzzy0ne[/eluser]
Can you be more specific?

What did you try?
What result did you expect?
What result did you get?
#3

[eluser]Tommy Liu[/eluser]
Thank you for your reply TheFuzzy0ne. I want to have result 'hello' string from function tabletojson in class Udpwebdb.

My current result is blank page in browser. Thanks.
#4

[eluser]TheFuzzy0ne[/eluser]
Sorry, I've just spotted your problem. $this is a variable, so it needs to be prefixed with a '$'.

In your index.php file, if you add the following to the top, it will enable error reporting and show you the problem:

Code:
error_reporting(E_ALL):
ini_set('display_errors', '1');

Just remember to disable it when your app goes live.
#5

[eluser]Tommy Liu[/eluser]
TheFuzzy0ne - I try to put the lines that you provided but the browser still blank.
#6

[eluser]TheFuzzy0ne[/eluser]
Did you put it inside your PHP tags? That should be enough to display PHP errors, and has worked for me and everyone else who uses it.

Have you enabled logging and made your ./application/log directory writable? What does your log say?

Also, did you substitute:
Code:
this->updwebdb->tabletojson()

with:
Code:
$this->updwebdb->tabletojson()

#7

[eluser]Tommy Liu[/eluser]
TheFuzzy0ne - Thank you for your keeping post to me. I try to re-download the latest version of CI to use. It works now. The last version of CI that I used is CI 2.1. thank you.




Theme © iAndrew 2016 - Forum software by © MyBB