简体   繁体   中英

RedBean simple model random id's

I inherited a web project that has been developed using Zend Framwork and Redbean Simple Model, and I am not too familiar with these.

Pages seem to be generated dynamically to edit entities. The problem I am facing is that html elements in the dynamically generated pages sections appear to have randomly generated id attributes. Each time I reload a page, the elements will have different id's. The id's look like fo-1384467680734.

This is a problem for me, since I cannot write any css or any jquery code specific to some DOM elements. Maybe one solution would be to give specific css classes to elements I am targeting, but I don't even know if this is possible.

Did anyone ever face that problem? Did you find a solution?

The original company that developed the web site is not maintaining it anymore, and my client asked me to take care of it and fix a few things on it.

UPDATE:

To be more specific, there is form on the web site to add new retailers. So there is a Retailer entity which is related to the Retailers table in the database. As far as I understand from the code the form is generated dynamically based on some definitions in a class (see code below).

As you can see in the code, a retailer has a province and a region. There are dropdown lists on the form to select the province and the region when adding a new retailer. However, these dropdown lists are "dumb" and I would like to make them a bit more "intelligent" with some jQuery. I would like the region dropdown list to show only the regions that are within the selected province. It would be no problem for me to do this normally, except here I don't know how to access the dropdown lists. I would need them to have fixed id's or to be able to assign them classes, but I don't know how to do this in this context.

Retailer Definition:

Class Default_Model_retailers extends Appclass_Redbean_SimpleModel {
    /* Db fields properties 

     */

    public $type = "retailers";
     public function getEntityModel() {
        return $this;
    }

    public function getOrderClause()
    {
        return " 1 ORDER BY name ASC ";
    }    

    public function getListColModel() 
    {

        $cols = ( array(    
            0 => (object) array('headerLabel' => 'Nom', 'fieldName' =>'name', 'width' => 110),  
            1 => (object) array('headerLabel' => 'Adresse', 'fieldName' => 'address_', 'width' => 110, 'type' => 'multiFields', 'fieldsList' => 'address.address2'), 
            //1 => (object) array('headerLabel' => 'Adresse', 'fieldName' => 'address', 'width' => 20),             
            2 => (object) array('headerLabel' => 'Code Postal', 'fieldName' =>'postcode', 'width' => 20),
            3 => (object) array('headerLabel' => 'Province', 'fieldName' =>'province_id', 'width' => 50, 'type'=>'one2one', 'table.label'=>'provinces.abbrev'),
            //3 => (object) array('headerLabel' => 'Province', 'fieldName' =>'province_id', 'width' => 50),
            4 => (object) array('headerLabel' => 'Ville', 'fieldName' =>'city', 'width' => 50),
            5 => (object) array('headerLabel' => 'Lat', 'fieldName' =>'latitude', 'width' => 50), 
            6 => (object) array('headerLabel' => 'Actions', 'fieldName' =>'actions', 'width' => 100)             
         ));
        return $cols;
    }

    public function getDefinition() {
        $exp = (object) array(
                    'id' => (object) array(
                        'label' => 'id',
                        'type' => 'refid'
                    ),
                    'name' => (object) array(
                        'label' => 'Nom du revendeur',
                        'type' => 'text'
                    ),
                    'address' => (object) array(
                        'label' => 'Adresse',
                        'type' => 'text'
                    ),
                    'address2' => (object) array(
                        'label' => 'Adresse Ligne 2',
                        'type' => 'text'
                    ),            
                    'city' => (object) array(
                        'label' => 'Ville',
                        'type' => 'text'
                    ),
                    'province_id' => (object) array(
                        'label' => 'Province',
                        'type' => 'select',
                        'subtype' => 'provinces',
                        'subtype_label' => 'name_fr'
                    ),
                    'region_id' => (object) array(
                        'label' => 'Région administrative',
                        'type' => 'select',
                        'subtype' => 'regions',
                        'subtype_label' => 'name_fr'
                    ),            
                    'phone' => (object) array(
                        'label' => 'Tél. (XXX) XXX-XXXX ',
                        'type' => 'text'
                    ),
                    'postcode' => (object) array(
                        'label' => 'Code Postal (XXXXXX)',
                        'type' => 'text',
                        'filter' => 'postcode'
                    ),
                    'contact' => (object) array(
                        'label' => 'Personne Ressource',
                        'type' => 'text'
                    ),            
                    'latitude' => (object) array(
                        'label' => 'Latitude',
                        'type' => 'text'
                    ),
                    'longitude' => (object) array(
                        'label' => 'Longitude',
                        'type' => 'text'
                    )             
        );
        return $exp;
    }

    public function getListEditDefinition() {
        $exp = (object) array(
                    'id' => (object) array(
                        'label' => 'id',
                        'type' => 'refid'
                    ),
                    'name' => (object) array(
                        'label' => 'Nom du revendeur',
                        'type' => 'text'
                    )             
        );

        return $exp;
    }

    public function getProvince()
    {
        $province = R::load('provinces', $this->province_id);
        return $province;
    }
}

There are also similar classes for the province and the regions entities. I won't post that code for now not to make this post too heavy, but I could if need be.

first of all this issue seems to be related more to HTML development then to RedBean itself. The Id of the element doesn't necessary has to be the Bean-ID. Secondly I'd argue go with CSS classes instead ids, that way you can leverage css styles accross multiple elements, or at least group the common formatting for some of them.

Without any further code I guess there will be a hard chance of helping you here

UPDATE: I've not worked yet with Zend Framework, but it uses widgets or similar to create elements. So your provided Model defines the general properties for a widget as it seems. Since you said you're creating Dropdowns, maybe somewhere in code a passage like this is existing:

$retailer = new Zend_Form_Element_Select('retailer');
or
$retailer = $form->addElement('select', ...);

so a quick google search came up with things like following to setup the id:

$retailer->setAttrib('id', 'retailerBox');
$retailer = $form->addElement('select', 'attribs' =>   array(
                            'id'=>'retailerBox',
                        ), ...);

Here are a few links I found which maybe help you with your task

Zend_Form QuickStart

Zend Form Decorators

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM