Magento model->save() does not work - magento

I am using following code for saving data from form to database.
$data = $this->getRequest()->getPost();
$custom['name'] = $data['name'];
$model = Mage::getModel('my/custom_order');
$model->setOrderId($order_id);
$model->setKey('name');
$model->setValue(serialize($custom));
$model->save();
Data does not save in database.But When I pass static data like below, It is Working.
$custom['name'] = 'John';
When I use print_r($data),
Array(
[name] => xyz
[surname] =>
)

Maybe you need:
$data = $this->getRequest()->getPost()->getParams();
Please check this. Check data which sended to server in your browser Network tool.

You need
$params = json_decode(file_get_contents('php://input'));

Related

update data to database laragon using api

I want to update data to the database in ionic. how to make the data update. Here what I tried. I try using postmen to post the api and it appear success but the data does not change.
in api.php
public function update (Request $request)
{
$id = $request->id;
$medname = $request->medname;
$price = $request->price;
$stock = $request->stock;
$medno = $request->medno;
$ingredient = $request->ingredient;
$description = $request->description;
$addinfo = $request->addinfo;
AddMedicine:: where('medname',$medname)->update([
'id' =>$id,
'medname'=>$medname,
'price'=>$price,
'stock'=>$stock,
'medno'=>$medno,
'ingredient'=>$ingredient,
'description'=>$description,
'addinfo'=>$addinfo,
]);
$msg = "Data Updated";
$datamsg = response()->json([
'success' => $msg
]);
return $datamsg->content();
}
route
Route::put('/update','ApiController#update');
Are you sure use PUT request ? Because need to CSRF token please inspect
https://stackoverflow.com/questions/30756682/laravel-x-csrf-token-mismatch-with-postman

Laravel: how to update records values coming as arrow

I am new to Laravel and I need to update records coming as array from a form.
$a = $request->id;
$b = $request->val;
Now I need to update the records
Details::find($b)->update(['detail'=>$a]);
The script above obviously does not work...
You can do it in more than one way, try this :
$details = Details::find($request->input($id));
$details->val = $request->input('val');
$details->save();
Or you can use this if the inputs has the same name as the model fields:
$details = Details::findOrFail($request->input($id));
$details->update($request->all());
You can update in the following ways. Assuming detail is your field name to update.
$id = $request->id;
$val = $request->val;
$detail = Details::findOrFail($id);
$detail->detail = $val;
$detail->save();
For the below to work. You need to set the $fillable propery in the model
// In Detail model
protected $fillable = ['detail'];
// Controller
Details::where('id', $id)->update([
'detail' => $val
]);
$a = $request->id;
$b = $request->val;
$detail = Detail::where('id', $a)->first();
$detail->update(['detail' => $b]);

How to check if data exsists in the database so you can update it

This code above adds data to the database but it does not update if the data already exsists.
public function updateStudentPastoral(){
// Getting all post data
$data = Input::all();
$pCollection = new PastoralCollection();
$pCollection->fill($data);
$response = '';
if ($pCollection->save())
$response = 'success';
else
$response = 'error';
return (json_encode($response));
}
i want to check if the data already exists so i will update it in the database but if it does exist it will save in the database.
You can use the laravel firstOrnew method like so:
$user = User::firstOrNew(array('name' => Input::get('name')));
$user->foo = Input::get('foo');
$user->save();
This will check if there is a record matching name if there is it will be updated otherwise a new one will be createad.

Connecting with multiple resources in PHRETS

I have to retrieve the data from multiple resources by using the Rets server. Is there any way to do so?
For example,
I have resources and classes like:
Property(Resource), Listing(Class)
Media(Resource), Media(Class)
Some data should be fetched from the first and a little bit from the second.
I am using the Phrets to retrieve the data from the Rets server.
I am using the source code:
<?php
date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
$log = new \Monolog\Logger('PHRETS');
$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
$config = new \PHRETS\Configuration;
$config->setLoginUrl('Url to connect with')
->setUsername('Username to login')
->setPassword('Password to login');
->setRetsVersion('1.5')
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
$connect = $rets->Login();
$resource = 'Property';
$class = 'Listing';
$query = "(Acres=0+)";
$options = array(
'Count' => 1,
'Format' => 'COMPACT-DECODED',
'Limit' => 50,
'StandardNames' => 0,
'Select'=>'Acres,City,ClosePrice,BathsFull,BathsHalf,PhotoCount,VirtualTourLink'
);
$results = $rets->Search($resource,$class,$query,$options);
foreach($results as $record){
echo "<table>";
echo "<tr>";
echo "<td>".$record['Acres']."</td>&nbsp";
echo "<td>".$record['City']."</td>";
echo "<td>".$record['ClosePrice']."</td>";
echo "<td>".$record['BathsFull']."</td>";
echo "<td>".$record['BathsHalf']."</td>";
echo "<td>".$record['VirtualTourLink']."</td>";
echo "</tr>";
echo "</table>";
}
?>
Thanks in advance!
Fetch your records from the first class and then fetch your records from the second class using the second classes dependent id. Media classes are always dependent on the property classes, so it will have some id that corresponds to the main id of the property class (usually the mls # of the listing). Without seeing your RETS server's metadata I won't be able to tell you the names of the fields you need to pull from. Also, your version is more than likely 1.7.2, AFAIK no one really uses 1.5 anymore.
You can fetch by using loop of class name.
$resource = 'Property';
$classes = array('Listing','Media');
$query = "(Acres=0+)";
$options = array(
'Count' => 1,
'Format' => 'COMPACT-DECODED',
'Limit' => 50,
'StandardNames' => 0,
'Select'=>'Acres,City,ClosePrice,BathsFull,BathsHalf,PhotoCount,VirtualTourLink'
);
foreach($classes as $class){
$results[$class] = $rets->Search($resource,$class,$query,$options);
}

Codeigniter variable not found message in sub views

I have stacked with the situation , please anyone help me !
Controller ->
public function index() {
$data = array();
$data ['tittle'] = 'Membership Payment';
$data ['page'] = $this->load->view('membership_payment', $data, true);
$data ['breadcrumb'] = $this->load->view('breadcrumb', $data, true);
$data['result'] = $this->payment_model->membership_payment();
$data['db']='---------------';
$this->load->view('master', $data);
View->master page
<?php echo $db; ?>
Master pages working fine , but problem is i have subpages membership_payment , in this page the data array variable are not working ,
Display the variable not found , there is any trick to pass data array to master subpage
Thanks in Advance !
ROB
I'm assuming that you've used $result which is the returned data of membership_payment(); method in the membership_payment view file.
If so, just change the order of the following line and put that over the $data['page'], as follows:
// ...
$data['result'] = $this->payment_model->membership_payment();
$data ['page'] = $this->load->view('membership_payment', $data, true);
// ...

Resources