i have cool component joomla me register users creating url (see link). joomla extention
what able write on different table using same method: code user registration:
//http://yoursite.com/index.php?option=com_hoicoiapi&task=registration&name=name&username=username&passwd=password&email=email public function registration() { $name = jrequest::getvar('name'); $username = jrequest::getvar('username'); $passwd = jrequest::getstring('pass'); $email = jrequest::getvar('email'); $data = array( "name"=>$name, "username"=>$username, "password"=>$passwd, "password2"=>$passwd, "email"=>$email, "block"=>1, "groups"=>array("2"), "sendemail"=>("1"), ); $user = new juser; //write database if(!$user->bind($data)) { $status = "could not bind data. error: " . $user->geterror(); } if (!$user->save()) { $status = "could not save user. error: " . $user->geterror(); } else { $status = "success"; } $message = array( 'message' => $status ); header('content-type: application/json'); echo json_encode ($message); jexit(); }
to more explicit, able write comments in table called belvw_zoo_comment there way modifying above code? m thinking of this:
//http://yoursite.com/index.php?option=com_hoicoiapi&task=comment&author=author&email=email&content=content public function comment() { $author = jrequest::getvar('author'); $email = jrequest::getvar('email'); $content = jrequest::getvar('content'); $data = array( "author"=>$author, "email"=>$email, "content"=>$content, ); $comment = new comment; //write database if(!$comment->bind($data)) { $status = "could not bind data. error: " . $user->geterror(); } if (!$comment->save()) { $status = "could not save user. error: " . $user->geterror(); } else { $status = "success"; } $message = array( 'message' => $status ); header('content-type: application/json'); echo json_encode ($message); jexit(); }
of course above code not working.
in beginning of code add:
$comment = jrequest::getvar('comment');
then inside success clause add following block
$db = jfactory::getdbo(); $query = $db->getquery(true); $query->insert('#__zoo_comment'); $query->set('name_of_field = '.$db->quote($comment)); $db->setquery( $query ); $db->execute();
you have change name of 'name_of_field' name of field , assumes comment in field called 'comment' in form submitted.
so get:
public function registration() { $name = jrequest::getvar('name'); $username = jrequest::getvar('username'); $passwd = jrequest::getstring('pass'); $email = jrequest::getvar('email'); $comment = jrequest::getvar('comment'); $data = array( "name"=>$name, "username"=>$username, "password"=>$passwd, "password2"=>$passwd, "email"=>$email, "block"=>1, "groups"=>array("2"), "sendemail"=>("1"), ); $user = new juser; //write database if(!$user->bind($data)) { $status = "could not bind data. error: " . $user->geterror(); } if (!$user->save()) { $status = "could not save user. error: " . $user->geterror(); } else { $status = "success"; //save comment $db = jfactory::getdbo(); $query = $db->getquery(true); $query->insert('#__zoo_comment'); $query->set('name_of_field = '.$db->quote($comment)); $db->setquery( $query ); $db->execute(); } $message = array( 'message' => $status ); header('content-type: application/json'); echo json_encode ($message); jexit(); }
Comments
Post a Comment