本文整理汇总了PHP中Sample::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Sample::save方法的具体用法?PHP Sample::save怎么用?PHP Sample::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sample
的用法示例。
在下文中一共展示了Sample::save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSavesample
public function getSavesample()
{
// DB::table('sample')->insert(array('name'=>"jeth"));
$sample = new Sample();
$sample->name = "jimbo";
$sample->save();
return "inserted";
}
示例2: actionCreate1
public function actionCreate1()
{
$model = new Sample();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Sample'])) {
$model->attributes = $_POST['Sample'];
if ($model->save()) {
$this->redirect('/adminDatasetSample/create1');
}
}
$this->render('create1', array('model' => $model));
}
示例3: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Sample;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Sample']))
{
$model->attributes=$_POST['Sample'];
if($model->save())
$this->redirect(array('view','id'=>$model->sno));
}
$this->render('create',array(
'model'=>$model,
));
}
示例4: testBehaviorSaveCallbacks
/**
* testBehaviorSaveCallbacks method
*
* @return void
*/
public function testBehaviorSaveCallbacks()
{
$Sample = new Sample();
$record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
$Sample->create();
$this->assertSame(false, $Sample->save($record));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
$Sample->create();
$result = $Sample->save($record);
$expected = $record;
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
$Sample->create();
$result = $Sample->save($record);
$expected = $record;
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
$expected = Hash::insert($record, 'Sample.name', 'sample99 modified before');
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->disable('Test');
$this->assertSame($record, $Sample->save($record));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
$expected = Hash::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertEquals($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
$expected = Hash::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
$Sample->create();
$expected = $record;
unset($expected['Sample']['name']);
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
$Sample->create();
$expected = $record;
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
$Sample->recursive = -1;
$record2 = $Sample->read(null, 1);
$Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
$expected = Hash::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
$Sample->create();
$this->assertSame($expected, $Sample->save($record2));
$Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
$expected = Hash::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
$Sample->create();
$this->assertSame($expected, $Sample->save($record2));
}
示例5: testBehaviorSaveCallbacks
/**
* testBehaviorSaveCallbacks method
*
* @access public
* @return void
*/
function testBehaviorSaveCallbacks()
{
$Sample = new Sample();
$record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
$Sample->create();
$this->assertIdentical($Sample->save($record), false);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
$expected = Set::insert($record, 'Sample.name', 'sample99 modified before');
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->disable('Test');
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
$expected = Set::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
$expected = Set::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
$Sample->recursive = -1;
$record2 = $Sample->read(null, 1);
$Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
$expected = Set::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
$Sample->create();
$this->assertIdentical($Sample->save($record2), $expected);
$Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
$expected = Set::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
$Sample->create();
$this->assertIdentical($Sample->save($record2), $expected);
}
示例6: addSample
public function addSample($songID)
{
$song = Song::find($songID);
if ($song == null) {
return Redirect::route('albums-home')->with('fail', "That song doesn't exist.");
}
if (Input::get('sample-artist') == '') {
return Redirect::route('albums-home')->with('fail', "Please enter Artist Name.");
}
if (Input::get('sample-title') == '') {
return Redirect::route('albums-home')->with('fail', "Please enter Song Title.");
}
$sample = new Sample();
$sample->song_id = $songID;
$sample->sample_artist = Input::get('sample-artist');
$sample->sample_title = Input::get('sample-title');
$sample->author_id = Auth::user()->id;
$action = new Action();
$action->song_title = $song->title;
$action->action = "Added sample";
$action->user_id = Auth::user()->id;
if ($sample->save() && $action->save()) {
return Redirect::route('albums-home')->with('success', 'The sample was added.');
} else {
return Redirect::route('albums-home')->with('fail', 'An error occured while saving the sample.');
}
}
示例7: Filesystem
<?php
require '../../computervision/config/common_require.php';
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
$filemanager = new Filesystem(new Adapter(__DIR__ . "/" . DIR_SIGNS));
$files = $filemanager->listContents("/samples");
foreach ($files as $file) {
//$samples_img[]=DIR_SIGNS.'/samples/'.$sample['basename'];
echo "Guardando archivo: " . $file['basename'] . "<br>";
$sample = new Sample();
$sample->image = $file['basename'];
$sample->save();
}
示例8: actionAddSample
public function actionAddSample()
{
if (isset($_POST['dataset_id']) && isset($_POST['sample_name']) && isset($_POST['species'])) {
$transaction = Yii::app()->db->beginTransaction();
try {
if ($_POST['sample_name'] == "") {
Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "Sample ID" value.')));
}
if ($_POST['species'] == "") {
Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "valid species" value.')));
}
$array = explode(":", $_POST['species']);
$tax_id = $array[0];
$species = Species::model()->findByAttributes(array('tax_id' => $tax_id));
if (!$species) {
Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "valid species" value.')));
}
#create new sample
$sample = new Sample();
$sample->species_id = $species->id;
$sample->name = $_POST['sample_name'];
$sample->submitted_id = Yii::app()->user->id;
$sample->submission_date = date('Y-m-d H:i:s');
$user = User::model()->findByPk(Yii::app()->user->id);
if ($user) {
$sample->contact_author_name = $user->first_name . " " . $user->last_name;
$sample->contact_author_email = $user->email;
}
if ($sample->save()) {
#create dataset sample
$ds = new DatasetSample();
$ds->dataset_id = $_POST['dataset_id'];
$ds->sample_id = $sample->id;
if ($ds->save()) {
$transaction->commit();
Util::returnJSON(array("success" => true));
}
}
Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Save Error.")));
} catch (Exception $e) {
$message = $e->getMessage();
Yii::log(print_r($message, true), 'error');
$transaction->rollback();
Util::returnJSON(array("success" => false, "message" => Yii::t("app", 'Cannot add sample, please input "valid species" value.')));
}
}
}