Retrieving PK Id on draft [table]_edit.php?

Login or register to post comments
9 replies [Last post]
Offline
Joined: 06/24/2009

Hi,

Is there any general method to get the PK Id value on the current record shown?

I currently use $_SERVER['PATH_INFO'] to extract the PK Id but I feel it should be some better way to retrieve the PK Id value

Thanks,

/Thomas

alex94040's picture
Offline
Joined: 11/06/2008

This depends on the name of the object you are doing [table]_edit.php on. For pre-generated form drafts, there's a Form_Create() method; in that method, you'll see something like

$this->mctActor = ActorMetaControl::CreateFromPathInfo($this);

(note that the code above was generated for the table called "actor")

After this line, you can get the Id field of of the "current" record by accessing

$intCurrentId = $this->mctActor->Actor->Id;

Offline
Joined: 06/24/2009

Alex, thanks for the quick response.

Yes of course it makes sense, i earlier tried:

$this->mctActor->Id; with no success. I did not find any information about how to retrieve PK id.

Since $_SERVER["PATH_INFO"] is empty and is not set when in create mode it is not a good way to get the PK id.

I'm really getting the Qcubed concept this time. I looked at qcodo for some time back, but did not quit get it (did not had time to look any deeper then). But now I've seen the light! Great!

I've succeeded to implement most of the function i want, but i still have autocomplete, filtered ajax search in datagrid left, hence the need of v1.1.

I've also been looking at the examples and in the documentation for a method to hyperlink a column to the edit page.

senario:

a datagrid with 3 columns: customer_name, customer_address, customer_order.

I want to hyperlink each column to the table specific edit_page. I already using the metadatagrid with the _edit_ for the main table hyperlink but need to figure out how to create hyper link to the foreign tables in this example customer, address and order.

I do not need a solution only some pointers were to get the information.

Keep up the good work! I hope i can contribute in the future, for now i'm just a newbie.

/Thomas

alex94040's picture
Offline
Joined: 11/06/2008

Thomas, the best way for you to get going would be to read through the MetaDataGrid examples - and actually yourself read through the code of the generated datagrids.

http://examples.qcu.be/assets/_core/php/examples/other/meta_datagrids.php.

Offline
Joined: 06/24/2009

Alex,

That was exactly what i meant; just a pointer were i can get the info, not a solution of my problem.

Thanks,

/Thomas

Offline
Joined: 06/24/2009

Alex,

I think you misunderstood me what i was trying to solve. The example does only show a method to catch click on current project record, not a foreign table. I looked at the API and searched for some clue how to do this but with no success.

Can i kindly ask for an example? Please...when you got the time or possibility.

/Thomas

Offline
Joined: 04/14/2008

Thomas,

If I correctly understood, you have a datagrid for a table that have relationship with other tables, and you need columns in the datagrid that pointing to this FK edit pages. In this case you need manually create columns in your datagrid.

Without more information about your model, I' supposing you have tables Order and Address, with Order.AddressId pointing to Address.Id.

In this case, I think you can do something like this:

$this->dtgOrders->AddColumn(new QDataGridColumn('Address'
, '< a href="' . __VIRTUAL_DIRECTORY__ . '/addresses_edit.php/< ?= $_ITEM->AddressId ?>">< ?= $_ITEM->Address ?>< /a>'
, 'Width=20'
, array( 'OrderByClause' => QQ::OrderBy(QQN::Orders()->Adderss)
, 'ReverseOrderByClause' => QQ::OrderBy(QQN::Orders()->Address, false)
)
, 'HtmlEntities=false'
)
);

or you can create methods in your OrderDataGrid class (in your __DATA_META_CONTROLS__ configurated directory) that implement this functionality. In my opinion, this is the best aproach. You can utilize OrderDataGridGen as start point.

Sorry for my english.

Offline
Joined: 06/24/2009

jucope,

This is exactly what i wanted to do. Now when I see the code i remember reading the datagrid variables on a tutorial page, but did not connect the dots.

Perhaps the examples should be extended with this type of hyperlink in a datagrid? And perhaps a method for creating hyperlink items in a datagrid should be in the class directly?

Thanks again, hope i can return the favor.

/Thomas

Offline
Joined: 03/31/2008

It would be great if the default templates automatically linked to foreign object's edit pages. I think it should be a simple change to QQNode::GetDataGridHtml, except for the fact that the URL to link to must be customizable by app.

I've created a ticket at http://trac.qcu.be/projects/qcubed/ticket/293.

Offline
Joined: 06/24/2009

Exactly, Now i've hardcoded every foreign object to link to its parent table in the datagrid and since i got +50 tables with references to foreign tables it a time consuming work that could/should be able to be autogenerated with the code generator.

Greate to know it will be added so future DB-projects will be less time consuming to realize. If the link could be adjusted in a easy way.

/Thomas