No records found …Agiletoolkit and Oracle. Grid/CR

2019-09-14 06:19发布

问题:

I am trying to test around Agile Toolkit with oracle, after seting up a model and trying to show a grid it says "No records found"...

Let me tell you what I did, since i've been guessing most of all configuration as I found no guides for oracle.

  • My Oracle connection string in agiletoolkit config-default.php file looks like this:

    $config['dsn']= array( 'oci:dbname=localhost/MYDATABASE', 'MYUSER', 'MYPASSWORD' );

  • To fix the driver not found error, I enabled extension=php_pdo_oci8.dll in the php.ini file from my apache installation.

  • Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:

    class DB_dsql_oci extends DB_dsql {
        function limit($cnt,$shift=0){
            $cnt+=$shift;
    
        $this->where('NUM_ROWS>=',$shift);
            $this->where('NUM_ROWS<',$cnt);
            return $this;
        }
        function render_limit(){
            return '';
        }
    }
    

and placed it at: ...atk4\lib\DB\dsql

  • To fix the special chars error from oracle , I set line 59 on /atk4/lib/DB/dsql.php to empty string like this: public $bt='';

I manage to run the database test, and it says "Successfully connected to database."

Then I created a model "lib\Model\Mytable.php" like this:

    <?php
    class Model_Mytable extends Model_Table {
        public $table = "MYTABLE";
        function init(){
            parent::init();

            $this->addField('ID');
            $this->addField('NAME');
            $this->addField('INIDATE');
            $this->addField('ENDDATE');     


        }
?>

After that, I made a new page and tried to use the model like this:

<?php
    class page_test extends Page {
    function init(){
        parent::init();


    $form = $this->add('Grid');
    $form->setModel('Mytable');



    }
}
?>

After refreshing the browser, it will show the grid saying " No Records found"

I wonder whats happening, that table has records no doubt, all data is committed, and im sure oracle is parsing queries because if I miss a column name an oracle error will raise.

Any clue?

回答1:

This is how you can simply set DSQL as your View (Grid for example) data source:

class page_test extends Page_Basic
{
    function init()
    {
        parent::init();

        // DSQL
        $q = $this->api->db->dsql();
        $q->table('MYTABLE')
                ->field('DNAME')
                ->field('INIDATE');

        // Create grid and set DSQL as its data source
        $g = $this->add('Grid');
        $g->addColumn('DNAME');
        $g->addColumn('INIDATE');
        $g->setSource($q);

        // better add paginator too or your grid can become huge :)
        $g->addPaginator();
    }
}