Recent Topics

Trying to add new db fields

Started by on Aug 10, 2008 – Contents updated: Aug 10, 2008

Aug 10, 2008 07:30    

There are 3 new inactive fields in evo_categories table in b2evo-2.5
cat_description
cat_longdesc
cat_icon

I want to "activate" them, but I don't know how :(

What I've done so far:
- Modified cat_load_cache() function in _category.funcs.php, it loads all fields now, and I already use them on site.
- Added new input fields in views/_chapter.form.php and they display correct values from db

But nothing happens when I save changes. I'm pretty sure that I have to add new fields in _chapter.class.php but I don't know what and where.

Thanks in advance.

Aug 10, 2008 09:16

Try playing with this section of code ;)

PHP

/**
     * Load data from Request form fields.
     *
     * @return boolean true if loaded data seems valid.
     */
    function load_from_request()
    {
        global $DB;
 
        parent::load_from_Request();
 
        // Check url name
        if( param_string_not_empty'cat_urlname'T_('Please enter an urlname.') ) )
        {
            $this->set_from_Request'urlname' );
            if( ! preg_match'|^[A-Za-z0-9\-]+$|'$this->urlname )
                    || preg_match'|^[A-Za-z][0-9]*$|'$this->urlname ) ) // This is to prevent conflict with things such as week number
            {
                param_error'cat_urlname'T_('The url name is invalid.') );
            }
            else
            {
            if( Chapter::urlname_exists$this->urlname$this->ID ) )
                { // urlname is already in use
                    param_error'cat_urlname'T_('This URL name is already in use by another category. Please choose another name.') );
                }
            }
        }
 
        return ! param_errors_detected();
    }

¥

Aug 10, 2008 09:37

I tried to add there $this->set_from_Request( 'description' ) but the object has empty properties.

'description' => NULL, 'longdesc' => NULL,

p.s. I already changed this function

PHP

function Chapter$db_row NULL$subset_ID NULL )
{
    // Call parent constructor:
    parent::GenericCategory'T_categories''cat_''cat_ID'$db_row );
 
    if( is_null($db_row) )
    {    // We are creating an object here:
        $this->set'blog_ID'$subset_ID );
        
    }
    else
    {    // Wa are loading an object:
        $this->blog_ID $db_row->cat_blog_ID;
        $this->urlname $db_row->cat_urlname;
        $this->description $db_row->cat_description;
        $this->longdesc $db_row->cat_longdesc;
        $this->icon $db_row->cat_icon;
    }
}

Aug 10, 2008 09:42

Do you think it would be easier to make a simple sql query and wait for a new release :roll: ?

Aug 10, 2008 10:16

Ok, fine I'll post the hack to update those new fields

Aug 10, 2008 12:15

This code is for update process only.

inc/chapters/chapters.ctrl.php starting line 220

PHP

// LOAD FORM DATA:
if( $edited_GenericCategory->load_from_Request() )
{    // We could load data from form without errors:
    // Update in DB:
    
    $sql 'UPDATE T_categories SET
                cat_description = '.$DB->quote($_POST['cat_description']).',
                cat_longdesc = '.$DB->quote($_POST['cat_longdesc']).',
                cat_icon = '.$DB->quote($_POST['cat_icon']).'
            WHERE cat_ID = '.get_param('cat_ID');
    
    $success1 $edited_GenericCategory->dbupdate();
    $success2 $DB->query($sql);
    
    if( $success1 !== false || $success2 !== false )
    {
        $Messages->addT_('Element updated.'), 'success' ); //ToDO change htis
    }
    // Add the ID of the updated element to the result fadeout
    $result_fadeout[$edited_GenericCategory->dbIDname][] = $edited_GenericCategory->ID;
    $action 'list';
}


Form is loading...

powered by b2evolution – This forum is powered by b2evolution CMS, a complete engine for your website.