<?php
if (isset($_POST["followid"]) && $_POST["action"] == "unfollow"){
$path = MODX_CORE_PATH . 'components/follows/';
$result = $modx->addPackage('follows',$path .
'model/','mgc_');
if (! $result) {
return 'Failed to add package';
}
$user = $modx->getUser();
$user_id = $user->get('id');
$follow_id = (int)$_POST["followid"];
$fields = array(
'user_id' => $user_id,
'follow_id' => $follow_id
);
$unfollow= $modx->getObject('Follows', $fields);
if ( $unfollow->remove() == false) {
echo "error";
}
else{
echo "ok";
}
}
?>
This question has been answered by lightweight30. See the first response.
if (! $unfollow) {
echo "could not get Follows object";
}<?xml version="1.0" encoding="UTF-8"?> <model package="follows" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1"> <object class="Follows" table="follows" extends="xPDOSimpleObject"> <field key="user_id" dbtype="int" precision="10" phptype="integer" null="false" index="index" /> <field key="follow_id" dbtype="int" precision="10" phptype="integer" null="false" /> <index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE" > <column key="user_id" length="" collation="A" null="false" /> <column key="follow_id" length="" collation="A" null="false" /> </index> </object> </model>
<?xml version="1.0" encoding="UTF-8"?> <model package="follows" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1"> <object class="Follows" table="follows" extends="xPDOSimpleObject"> <field key="user_id" dbtype="int" precision="10" phptype="integer" null="false" index="index" /> <field key="follow_id" dbtype="int" precision="10" phptype="integer" null="false" /> <index alias="id" name="id" primary="true" unique="true" type="BTREE" > <column key="id" length="" collation="A" null="false" /> </index> </object> </model>