OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



mysql data

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

mysql data

Postby jjgitties » Tue Nov 19, 2013 9:37 am

Hi, I am working on developing a DOA to list mysql data. I can see that it's sort of working but its not returning the proper objects. its returning objects which I cant convert to strings.

My code in the tpl file is:

Code: Select all
 { iterate from=files item=file }
 <td> { $file -> getFileName() } </td>
</tr>
 {/iterate}


my code in the DOA is:

Code: Select all
      function &getFiles() {
                $sql = 'SELECT * FROM files';
                $result = &$this->retrieve($sql);
                $return = null;
                $return = new DAOResultFactory($result, $this, '_returnFilesFromRow');
               return $return;
        }

      function &_returnFilesFromRow($row) {
                $files = new Files();
                $files -> setFileName($row['file_name']);
//                $filename=print_r($filename);
                return $filename;
        }




My code in the FileName.inc is:

Code: Select all
       function getFileName() {
            return $this->getFileName('file_name');
        }

        function setFileName($file_name) {
                return $this->setData('file_name', $file_name);
        }


My code in the inc.php is:

Code: Select all
    function listFiles() {
        $tplMgr = &TemplateManager::getManager();

        $filesDao = &DAORegistry::getDAO('FilesDAO');
        $files = $FilesDao->getFiles();

        $tplMgr->assign('files', $files);
        $tplMgr->display('admin/files/listfiles.tpl');
     }

jjgitties
 
Posts: 20
Joined: Tue Nov 12, 2013 11:11 am

Re: mysql data

Postby asmecher » Tue Nov 19, 2013 11:47 am

Hi jjgitties,

Your _returnFilesFromRow function is returning a string when it should be returning the constructed $files object.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: mysql data

Postby jjgitties » Tue Nov 19, 2013 1:13 pm

You mean this one? My original post included a commented out print_r line which I was using to debug whats going on.


Code: Select all
      function &_returnFilesFromRow($row) {
                $files = new Files();
                $files -> setFileName($row['file_name']);
                return $filename;
        }


asmecher wrote:Hi jjgitties,

Your _returnFilesFromRow function is returning a string when it should be returning the constructed $files object.

Regards,
Alec Smecher
Public Knowledge Project Team
jjgitties
 
Posts: 20
Joined: Tue Nov 12, 2013 11:11 am

Re: mysql data

Postby asmecher » Tue Nov 19, 2013 3:40 pm

Hi jjgitties,

The $filename variable in that function is not defined anywhere.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: mysql data

Postby jjgitties » Tue Nov 19, 2013 8:05 pm

asmecher wrote:Hi jjgitties,

The $filename variable in that function is not defined anywhere.

Regards,
Alec Smecher
Public Knowledge Project Team



Thanks. It was a typo on my part. But it still fails to work even after fixing the changes. I think my problem is i don't understand how the DOA works. Is there an example of a proper way to use this? All I have is a database with a table. I just need to iterate over all the objects and show them in a web page. Which would be better to use in this situation? retrieve or retrieverange?

http://pkp.sfu.ca/ojs/doxygen/master/ht ... f78f029d5e

http://pkp.sfu.ca/ojs/doxygen/master/ht ... fa64519423
jjgitties
 
Posts: 20
Joined: Tue Nov 12, 2013 11:11 am

Re: mysql data

Postby asmecher » Tue Nov 19, 2013 8:36 pm

Hi jjgitties,

You're close, but I think there are still typos in your code. In your definition of the getFileName function, you're calling getFileName rather than getData, which will lead to an infinite loop. There are tons of examples in the code, of which the simplest may be something like classes/article/ArticleCommentDAO.inc.php and classes/article/ArticleComment.inc.php. Consistency is key -- watch out for inconsistent capitalization, and it looks like you're calling your files xxx.inc rather than xxx.inc.php. I know what you mean but your computer will not :)

retrieve and retrieveRange do nearly the same thing, but retrieveRange is used when you're paging between multiple pages of a result set. Stick with retrieve for now and deal with paging after you have this working.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: mysql data

Postby jjgitties » Thu Nov 21, 2013 7:31 pm

Thanks a bunch. The Article Comment code base did the trick.
jjgitties
 
Posts: 20
Joined: Tue Nov 12, 2013 11:11 am


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron