Magento Forum

getting instance of a model by attribute
 
Stephan Hoyer
Jr. Member
 
Total Posts:  12
Joined:  2009-02-03
Leipzig
 

To get a specific entry of the DB i do this

$collection Mage::getModel('navadmin/navadmin')->getCollection()
            ->
addFieldToFilter('title', array('='=>$title) )
            ->
addFieldToFilter('store_id', array('in'=>$store_id) )
            ->
addFieldToFilter('status', array('in'=>'1') );
        
        echo 
$collection->getSelect()->__toString();

which processes this output:

SELECT `main_table`.* 
FROM `navadmin` AS `main_table
WHERE (((title 'Item 1'))) AND (store_id in ('9')) AND (status in ('1')

which is exactly one entry if i run the query on the console

but if i then run

echo sizeof($collection->getData());
i got 0 as result.

what is the problem here?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stephan Hoyer
Jr. Member
 
Total Posts:  12
Joined:  2009-02-03
Leipzig
 

I did it right, but because i used the wysiwyg-module there where some html-tags in the title :(

but now i find an even shorter syntax…

$element Mage::getModel('navadmin/navadmin')
            ->
setStoreId($store_id)
            ->
load(strip_tags($title), 'title');
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top