0

I have some problems with my custom modul.

This is my config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Mymodule_Marques>
        <version>0.0.2</version>
    </Mymodule_Marques>
</modules>
<global>
    <blocks>
        <marques>
            <class>Mymodule_Marques_Block</class>
        </marques>
    </blocks>
    <helpers>
        <marques>
            <class>Mymodule_Marques_Helper</class>
        </marques>
    </helpers>
    <models>
        <marques>
            <class>Mymodule_Marques_Model</class>
            <resourceModel>mymodule_marques_resource</resourceModel>
        </marques>
        <mymodule_marques_resource>
            <class>Mymodule_Marques_Model_Resource</class>
            <entities>
                <marque>
                    <table>mymodule_marques</table>
                </marque>
            </entities>
        </mymodule_marques_resource>
    </models>
    <resources>
        <marques_setup>
            <setup>
                <module>Mymodule_Marques</module>
            </setup>
        </marques_setup>
        <mymodule_marques_read>
            <connection>
                <use>core_read</use>
            </connection>
        </mymodule_marques_read>
        <mymodule_marques_write>
            <connection>
                <use>core_write</use>
            </connection>
        </mymodule_marques_write>
    </resources>
</global>
<admin>
    <routers>
        <marques>
            <use>admin</use>
            <args>
                <module>Mymodule_Marques</module>
                <frontName>marques</frontName>
            </args>
        </marques>
    </routers>
</admin>
<adminhtml>
    <layout>
        <updates>
            <marques>
                <file>marques.xml</file>
            </marques>
        </updates>
    </layout>
</adminhtml>

this is my controller

<?php

class Mymodule_Marques_Adminhtml_MarquesController extends 
Mage_Adminhtml_Controller_Action {

public function _initAction() {
    $this->loadLayout()
            ->_setActiveMenu('cms');
    return $this;
}

public function indexAction() {
    $this->_title(Mage::helper('marques')->__('Choose store'));

    $this->_initAction()
            ->renderLayout();
    return;
}

public function clickAction() {
    $this->_title(Mage::helper('marques')->__('choose brands'));

    $this->_initAction()
            ->renderLayout();
    return;
}


public function editAction() {
    $this->_title(Mage::helper('marques')->__('edit brands'));

    $this->_initAction()
            ->renderLayout();
    return;
}


}

in my folder Block/Adminhtml , i create new folder Edit with this files: Tabs.php =>

<?php

class Mymodule_Marques_Block_Adminhtml_Edit_Tabs extends 
Mage_Adminhtml_Block_Widget_Tabs {

public function __construct() {
    parent::__construct();
    $this->setId('marques_tabs');
    $this->setDestElementId('edit_form');
}

protected function _beforeToHtml() {
  $cpt = 0;
    $blocks = Mage::helper("marques")->getBlocks(Mage::app()->getRequest()->getParam("store_id"));

    if($blocks){
        foreach ($blocks as $block) {
            $cpt++;
            $this->addTab('block_'.$cpt, array(
                'label' => Mage::helper('marques')->__('Block '.$cpt),
                'title' => Mage::helper('marques')->__('Block '.$cpt),
                'content' => $this->getLayout()->createBlock('marques/adminhtml_edit_tab_block')->setBlockNumber($cpt)->setBlock($block)->toHtml(),
            ));
        }
    }
    while ($cpt < 3) {
        $cpt++;
        $this->addTab('block_'.$cpt, array(
            'label' => Mage::helper('marques')->__('Block '.$cpt),
            'title' => Mage::helper('marques')->__('Block '.$cpt),
            'content' => $this->getLayout()->createBlock('marques/adminhtml_edit_tab_block')->setBlockNumber($cpt)->toHtml(),
        ));
    }
}

}

this is my file Form.php

<?php

class Mymodule_Marques_Block_Adminhtml_Edit_Form extends 
Mage_Adminhtml_Block_Widget_Form {

protected function _prepareForm() {
    $form = new Varien_Data_Form(array(
            'id' => 'edit_form',
            'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
            'method' => 'post',
            'enctype' => 'multipart/form-data'
        )
    );

    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

}

Abd i create a new folder in Edit, this name is Tab with file Block.php

<?php

class Mymodule_Marques_Block_Adminhtml_Edit_Tab_Block extends 
Mage_Adminhtml_Block_Widget_Form implements 
Mage_Adminhtml_Block_Widget_Tab_Interface {

protected function _prepareForm() {
    $form = new Varien_Data_Form();

    $fieldset = $form->addFieldset('block_'.$this->getBlockNumber().'_fieldset', array('legend' => Mage::helper('marques')->__("Block ".$this->getBlockNumber())));

    if ($this->getBlock()) {
        $fieldset->addField('marques_id', 'hidden', array(
            'name' => 'block['.$this->getBlockNumber().'][marques_id]'
        ));
        $fieldset->addField('store_id', 'hidden', array(
            'name' => 'block['.$this->getBlockNumber().'][store_id]',
        ));
    }else{
        $fieldset->addField('store_id', 'hidden', array(
            'name' => 'block['.$this->getBlockNumber().'][store_id]',
            'value' => Outdoordiffusion_Home_Model_Home_Type::TYPE_TROISBLOCS
        ));
        $fieldset->addField('type', 'hidden', array(
            'name' => 'block['.$this->getBlockNumber().'][type]',
            'value' => Mage::app()->getRequest()->getParam("store_id")
        ));
    }

    $fieldset->addField('image', 'image', array(
        'label' => Mage::helper('marques')->__('Image'),
        'name' => 'block'.$this->getBlockNumber().'_image',
        'required' => true,
        'note'  => $this->__("Dimensions : 376px x 218px.")
    ));

    $fieldset->addField('label', 'text', array(
        'label' => Mage::helper('home')->__('Label'),
        'name' => 'block['.$this->getBlockNumber().'][label]',
        'required' => true,
    ));

    $fieldset->addField('url', 'text', array(
        'label' => Mage::helper('marques')->__('Url'),
        'name' => 'block['.$this->getBlockNumber().'][url]',
        'required' => true,
    ));

    $fieldset->addField('position', 'text', array(
        'label' => Mage::helper('marques')->__('Position'),
        'name' => 'block['.$this->getBlockNumber().'][position]',
    ));

    $fieldset->addField('onclick', 'text', array(
        'label' => Mage::helper('marques')->__('Onclick'),
        'name' => 'block['.$this->getBlockNumber().'][onclick]',
        'note' => $this->__("Exemple : ga('send', 'event', 'event1', 'event1', 'event1');")
    ));



    if ($this->getBlock()) {
        $form->setValues($this->getBlock()->getData());
    }

    $this->setForm($form);
    return parent::_prepareForm();
}

public function getTabLabel() {
    return Mage::helper('marques')->__('Block '.$this->getBlockNumber());
}

public function getTabTitle() {
    return Mage::helper('marques')->__('Block '.$this->getBlockNumber());
}

public function canShowTab() {
    return true;
}

public function isHidden() {
    return false;
}

}

This my file marques.xml in design/adminhtml/layout

<?xml version="1.0"?>
<layout version="0.1.0">
<marques_adminhtml_marques_index>
    <reference name="content">
        <block type="marques/adminhtml_store" name="marques_store" />
    </reference>
</marques_adminhtml_marques_index>
 <marques_adminhtml_marques_click>
    <reference name="content">
        <block type="marques/adminhtml_click_marques" name="marques_grid" />
    </reference>
</marques_adminhtml_marques_click>
<marques_adminhtml_marques_edit>
    <reference name="left">
        <block type="marques/adminhtml_edit_tabs" name="marques_edit_tabs" />
    </reference>
</marques_adminhtml_marques_edit>
</layout>

And this is my helper how call my model marque

<?php

class Mymodule_Marques_Helper_Data extends Mage_Core_Helper_Abstract {


 public function getBlocks($storeId = null){

    $blocks = Mage::getModel("marques/marque")->getCollection();

    var_dump($blocks);

    echo get_class(Mage::getModel('marques/marque'));exit;


}



}

this is my MODEL with file marque and folder Resource and collection.php

<?php

class Mymodule_Marques_Model_Marque extends Mage_Core_Model_Abstract {

public function _construct() {

    parent::_construct();
    $this->_init('mymodule_marques/marque');

}

}

this is my resource

<?php

 class Mymodule_Marques_Model_Resource_Marque extends 
 Mage_Core_Model_Resource_Db_Abstract
 {
 public function _construct() {

    $this->_init('mymodule_marques/marque', 'marques_id');

 }
 }

and this is my collection

<?php

 class Mymodule_Marques_Model_Resource_Marque_Collection extends 
 Mage_Core_Model_Resource_Db_Collection_Abstract
 {
 protected  function _construct() {     

    parent::_construct();
    $this->_init('mymodule_marques/marque');

 }
  }

In my admin i have an errors this =>

$blocks = Mage::getModel("marques/marque")->getCollection(); return false

Can you help , what I do not see ????

Thank

2

You have not posted the Model, ResourceModel & Collection files. Do you have them in place or not ? If not, you have to create them in order to use collection.

Updated Answer

Change your Model file like this

<?php

class Mymodule_Marques_Model_Marque extends Mage_Core_Model_Abstract {

public function _construct() {

    parent::_construct();
    $this->_init('marques/marque');

}

}

Change your ResourceModel file like this

<?php

 class Mymodule_Marques_Model_Resource_Marque extends 
 Mage_Core_Model_Resource_Db_Abstract
 {
 public function _construct() {

    $this->_init('marques/marque', 'marques_id');

 }
 }

Change your Collection file like this

<?php

 class Mymodule_Marques_Model_Resource_Marque_Collection extends 
 Mage_Core_Model_Resource_Db_Collection_Abstract
 {
 protected  function _construct() {     

    parent::_construct();
    $this->_init('marques/marque');

 }
  }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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