开发者

add a name value pair to posted data for joomla to consume and insert into DB

I'm trying to use the Joomla framework to make a create in the main content table.[http://docs.joomla.org/How_to_use_the_JTable_class] This works fine except that some data comes from posted variables and some from logic that happens when a file is uploade开发者_JAVA技巧d moments before (store the random image name of a jpg)

$data=&JRequest::get('post');

this takes a ref to the posted values and I want to add to this Array or Object my field. The code I have makes the new record but the column images, doesnt get my string inserted.

I am trying to do something like$data=&JRequest::get('post'); $newdata=(array)$data; array_push($newdata,"images"=>"Dog");

i make newdata as data is a ref to the posted variables and i suspect wont there fore allow me to add values to $data. I'm a flash guy normally not a php and my knowledge is letting me down here.

Thanks for any help


Right, first thing:

$data=&JRequest::get('post');

$data is an array, you do not have to cast it. To add another element to the array as described in the comments do this:

$data['images'] = 'cats';

If you are using normal SQL to do the insert then you would do something like this to get the last inserted id e.g. the id of the row you just inserted:

$db = $this->getDBO();
$query = 'Some sql';
$db->setQuery($query);
if (!$db->query()) {
  JError::raiseWarning(100, 'Insert failed - '.$db->getErrorMsg());
}
$id = $db->insertid();

If you are developing in Joomla I suggest you use the db functions provided to you rather than mysql_insert_id();

[EDIT]

If you want to use store then you can get the last inserted id like so:

$row->bind($data);
$row->check();
$row->store();
$lastId = $row->id;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜