Recent Topics

1 Jan 29, 2008 14:43    

My b2evolution Version: 2.x

Hi,

at first - sorry for my english. :-)

If i want to insert a new category the system give her a new cat_ID automaticly by default.
I need to give the new category an own number, because i relate the categories to another table (outside from b2e). I tried this in the versions <2.x and it works. Now i'll upgrade to 2.4.0-RC2 but i can't solve the job with the cats. :-)
I found the "New Category"-Form in the /inc/chapters/views/-Folder. But i i insert a new Field for the cat_ID i ever get an error from chapters.control.php like "Requested element does not exist any longer.".

How can i solve my problem? Any ideas?

thank you in advance and greetings from germany
Joerg

2 Jan 29, 2008 15:37

Make sure you've specified all the fields, especially cat_parent ( NULL if no parent ) and cat_blog_ID.

This works for me [url=http://dev.innervisions.org.uk/blog1.php/yowza/]here[/url]

INSERT INTO `yabba_dev`.`evo_categories` (
`cat_ID` ,
`cat_parent_ID` ,
`cat_name` ,
`cat_urlname` ,
`cat_blog_ID` ,
`cat_description` ,
`cat_longdesc` ,
`cat_icon`
)
VALUES (
'14', NULL , 'my doozy category', 'yowza', '1', NULL , NULL , NULL
);

¥

3 Jan 29, 2008 16:32

Thanx for your reply, but its not the solution. ;-)

Let me explain my problem:
From the dashboard i go with "Edit categories »" to the categories. With "New category »" i want to create a new cat. In this form i have insert a new textbox called "cat_ID". I can see the textbox (defaultvalue is zero) and i put an integer in the box. Now i fill name and url and then i click on "record".
After this i get the error "Requested element does not exist any longer." from chapters.control.php. Why and what can i do now?

The next questions would be:
Its right that the function cat_create in /inc/collections/model/_category.funcs.php insert the new cat in the table?

If yes - how receive this function my own cat_ID?

Its suffice to add a param in this function (like new_cat_ID) and change the sql-statement if the $new_cat_ID is not empty?

Many thanx for your help!
I know something about php and mysql, but at this point i must surrender. ;-)

4 Jan 29, 2008 17:12

Hmmm, there's no real easy way to do that, but this is what I'd do.

I'd change the textbox to be called new_cat_ID instead of cat_ID ( otherwise the dbinsert() won't work ). Then I'd amend the current function in inc/chapters/model/_chapter.class.php ( approx 271 - 309 ) to change the ID after the record has been created :

	/**
	 * Insert object into DB based on previously recorded changes.
	 *
	 * @return boolean true on success
	 */
	function dbinsert()
	{
		global $DB;

		if( $this->ID != 0 ) die( 'Existing object cannot be inserted!' );

		$DB->begin();

		if( Chapter::urlname_exists( $this->urlname ) )
		{	// We gotta find another name:
			$sql = 'SELECT cat_urlname
								FROM T_categories
							 WHERE cat_urlname REGEXP "^'.$this->urlname.'(-[0-9]+)?$"';
			$highest_number = 0;
			foreach( $DB->get_results( $sql ) as $row )
			{
				if( preg_match( '/-([0-9]+)$/', $row->cat_urlname, $matches ) )
				{ // This one has a number, we extract it:
					$existing_number = (integer) $matches[1];
					if( $existing_number > $highest_number )
					{ // This is the new high
						$highest_number = $existing_number;
					}
				}
			}
			$this->set( 'urlname', $this->urlname.'-'.($highest_number+1) );
		}

		$r = parent::dbinsert();

		$DB->commit();
// change chapter ID
if( $this->ID != param( 'new_cat_ID', 'integer' ) && $new_cat_ID )
{ // we want to change the id
  $sql = 'UPDATE T_categories SET cat_ID = '.$new_cat_ID.' WHERE cat_ID = '.$this->ID;
  $DB->query( $sql );
  $this->ID = $new_cat_ID;
}
// end change chapter ID
		return $r;
	}

¥

5 Jan 29, 2008 22:28

Hmmm ... i have my problems with this. I renamed the textboxname to "newcatID".
Then i tried your code (with the new varname ;-) but i ever get an error, that $newcatID not exists. If i put something like "123xyz" into the textbox the validation generate an error because there is an invalid value (not integer, i think in line 226; /inc/_core/_param.funcs.php). If i put an integer in the box -> the value pass the validation. But in your code .... && $newcatID failed.

Ok - now i'm thinking that after the validation the VAR $newcatID is not generated. But why? Must i declare this var before? I don't think so. In your code you check the existing of the var after the param comparsion. If not exit, something was wrong with the value, right?

How can i fix this? Would you help me please again?

6 Jan 30, 2008 00:07

hmmm, I was sure the param() call would global the value, guess not, change the code slightly so it looks like this :

// change chapter ID
$new_cat_ID = param( 'new_cat_ID', 'integer' );
if( $this->ID != $new_cat_ID && $new_cat_ID )

¥

7 Jan 30, 2008 08:30

Great! It works!

Many thanx from here.


Form is loading...