1

In magento 1.9.1:

I'm building a system that includes a table with a FK pointing to a static block ID ( see cms_block table in Magento, that's the table I'm correlating to ). For the system to work dependably, I need to be able to store a record referencing the primary key on the cms_block table.

Put simply: I need a variation of $block->getBlockId() that always returns the primary key (an integer) associated with the static block in question.

It seems, as far as I can tell, $myBlock->getBlockId() returns an integer only if the block is invoked with an integer. If the block is invoked with its corresponding identifier string (a common scenario), it returns the identifier string instead.

Is there a way for me to get at that primary key without having to talk to the database directly?

Answer

Props to Rajeev K Tomy :)

Here is my code that got the job done:

    $model = Mage::getModel( 'cms/block' );
    $collection = $model->getCollection()
        ->addFieldToFilter( 'identifier', $this->getBlockId() );

    $block = $collection->getFirstItem();

    return $block->getId();

1 Answer 1

1

Try this to get the primary key of static block

/** $block Mage_Cms_Model_Block **/
$block->getId()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.