문제

I am submitting a form and getting result from model.I want to display the result in phtml file ie the whole collection after submitting need to be in phtml file

Here is my code

Controller

        $this->loadLayout();

    if($this->getRequest()->isPost())
    { 
        $post = $this->getRequest()->getPost();
        $data = array();
        $collection = Mage::getModel('searchservice/service')->getCollection();
        $collection->addFieldToFilter('compstate',array('eq'=>$post['input1']));

        Mage::getSingleton('core/session')->addSuccess(Mage::helper('searchservice')->__('Displaying Your Result'));
        $this->renderLayout();

    }

I want data in an aaray returned from collection filter and use in phtml with foreach.

도움이 되었습니까?

해결책

you can use magento registry for setting and getting values as:

set a value (in controller)

Mage::register('var_name',$var_value);

get a value (in phtml/view)

$var_value = Mage::registry('var_name');

more you can find at

http://alanstorm.com/magento_registry_singleton_tutorial
https://stackoverflow.com/a/18157176/725306

다른 팁

Here is the solution i found in Controller:

Mage::register('data', $collection);

in view

$data = Mage::registry('data');

so the code becomes

        if($this->getRequest()->isPost())
    { 
        $post = $this->getRequest()->getPost();
        $data = array();
        $collection = Mage::getModel('searchservice/service')->getCollection();
        $collection->addFieldToFilter('compstate',array('eq'=>$post['input1']));
        foreach ($collection as $record) 
        {
            $data[] = $record->getProfileurl();
        }
        Mage::register('data', $data);
        Mage::getSingleton('core/session')->addSuccess(Mage::helper('searchservice')->__('Displaying Your Result'));
        $this->renderLayout();

    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top