Error connecting to db


#1

Hi,

I trying to do a first connection a bd, but I receive this error. What I need to do to fix this error?

Fatal Error
atk4\core\Exception: Method is not defined for this object

Exception Parameters
• class: “atk4\ui\App”
• method: “dbConnect”
• arguments: [“mysql://root:@localhost/ait”]

This is my code:

<?php

require 'vendor/autoload.php';

$app = new \atk4\ui\App('Database');
$app->initLayout('Centered');

$db = $app->dbConnect('mysql://root:@localhost/ait');

class entidad extends \atk4\data\Model 
{
    public $table = 'entidad';
    function init() {
    	parent::init();
    	$this->addfield('conent');
    	$this->addfield('noment');
    	$this->addfield('ap1ent');
    }
}

$entidad = new entidad($db);
$entidad->LoadAny();

$table = $app->add('CRUD');
$table->SetModel($entidad);

Thanks


#2

Hi. This was a fix in the pipeline for 1.4.1 version of Agile UI.

I have updated www.agiletoolkit.org with this version now, so you can either re-download or run “composer update” in a command-line.


#3

Hi Romanish,

it works, but give a new error

Fatal Error
atk4\dsql\Exception: DSQL got Exception when executing this query

Exception Parameters
• error: “SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘id’ in ‘field list’”
• query: “select id,conent,noment,ap1ent from entidad limit 0, 1”

But, in my select, I don’t have any id column.

Can you help me?

Thanks,


#4

Agile Data is a persistence mapper - it maps your object to records in the database. In order to be able to save results, in requires it to have unique id field.

if that field is named differently, not id you can specify its name in id_field property, however you need one. There is a way to disable id but it only makes sense if you are aggregating data. This was introduced in Agile Data 1.2 (http://www.agiletoolkit.org/blog/agile-data-1-2-released).


#5

thanks id_field works!


#6

Hi,
when I try to Add with the Add Button, don’t works. Thw modal window appears with info, and works as Edit Mode, I think.

:frowning:

Something wrong with my code?


#7

yes, remove “loadAny”.

Actually CRUD should probably unload this during add (https://github.com/atk4/ui/issues/362)


#8

Gustavo, are you following the udemy tutorial? where did this line come from?


#9

Yes, I looking Udemy course. I have a new problem, I have several columns thats show fine in the grid, but in the modal view to add, only appears the two original fields, with I began my example code. ie. in the code you see noment and ap1ent (I delete conent, because is the id), later I add some fields more, but only appears noment and ap1ent in the modal window. :frowning:


#10

Gustavo, I’m not sure what could be the problem.

Try to see how those new fields are different to noment try changing things around. If you are stuck, post your code here again.

BTW - what do you think about udemy course so far?


#11

OK. I’m lost :frowning:
The course is very good, easy to understand. :wink:

My actual code:
require ‘vendor/autoload.php’;

$app = new \atk4\ui\App(‘Database’);
//$app = new App(‘My App’);
$app->initLayout(‘Centered’);

$db = $app->dbConnect(‘mysql://root:@localhost/ait’);
class entidad extends \atk4\data\Model
{
public $table = ‘entidad’;
public $id_field = ‘conent’;
function init() {
parent::init();

// $this->addfield(‘conent’);
$this->addfield(‘concia’);
$this->addfield(‘noment’);
$this->addfield(‘ap1ent’);
$this->addfield(‘entact’);
$this->addfield(‘maient’);
$this->addfield(‘tipid’);
$this->addfield(‘numid’);
$this->addfield(‘telent’);
}

}

$entidad = new entidad($db);

//$entidad->LoadAny();

$table = $app->add(‘CRUD’);

$table->SetModel($entidad);

I comments the LoadAny()

I delete my example data then the grid is empty. First Image.

Then try to add, and only appears two fields with some old data. Second Image.

And because I need to put some data in other fields I can’t add any register, because of data restriction controls.


#12

please clean yoru post, can’t read…


#13

I clean it :slight_smile:


#14

Hi, I’m following the Udemy course, I have Agile Toolkit 1.5.1 installed

in topic 5. Building User Admin page with CRUD, MySQL, Forms and Tables

I try to make a first connection to bd, but I get this error. How can I correct this error?

Fatal Error
atk4\core\Exception: Method is not defined for this object



I can not solve it and would like to continue the course
Thank you


#15

As per error, something is wrong on line 46 of your index.php. In your screenshot there are only 36 lines visible.


#16


the error seems to be in the method: “dbConnect”
I can not show the results table


#17

just delete line 22, you are already connecting on line 12.

I’m not sure where is this line from.


#18

when commenting on line 22 the errors continue


#19

did you modify it? looks like you have addField() instead of $this->addField()