本文整理汇总了PHP中Author::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::save方法的具体用法?PHP Author::save怎么用?PHP Author::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInvalidCharset
public function testInvalidCharset()
{
$this->markTestSkipped();
$db = Propel::getDB(BookPeer::DATABASE_NAME);
if ($db instanceof DBSQLite) {
$this->markTestSkipped();
}
$a = new Author();
$a->setFirstName("Б.");
$a->setLastName("АКУНИН");
$a->save();
$authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
$a->setLastName($authorNameWindows1251);
// Different databases seem to handle invalid data differently (no surprise, I guess...)
if ($db instanceof DBPostgres) {
try {
$a->save();
$this->fail("Expected an exception when saving non-UTF8 data to database.");
} catch (Exception $x) {
print $x;
}
} else {
// No exception is thrown by MySQL ... (others need to be tested still)
$a->save();
$a->reload();
$this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
}
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Book();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Book'])) {
$authordetails = Author::model()->findByAttributes(array('author_name' => $_POST['Book']['author']));
$publication = Publication::model()->findByAttributes(array('name' => $_POST['Book']['publisher']));
$model->attributes = $_POST['Book'];
if ($publication == NULL) {
$publisher = new Publication();
$publisher->name = $_POST['Book']['publisher'];
$publisher->save();
$model->publisher = $publisher->publication_id;
} else {
$model->publisher = $publication->publication_id;
}
if ($model->save()) {
//echo count($authordetails).$authordetails->auth_id; exit;
if ($authordetails) {
$model->author = $authordetails->auth_id;
$model->save();
} else {
$author = new Author();
$author->author_name = $_POST['Book']['author'];
$author->save();
$model->author = $author->auth_id;
$model->save();
}
$model->status = 'C';
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例3: makeAuthor
/**
* Helper to create "Author" model for tests.
*
* @param $name
* @return Author
*/
protected function makeAuthor($name)
{
$author = new Author();
$author->name = $name;
$author->save();
return $author;
}
示例4: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their corresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aAuthor !== null) {
if ($this->aAuthor->isModified() || $this->aAuthor->isNew()) {
$affectedRows += $this->aAuthor->save($con);
}
$this->setAuthor($this->aAuthor);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
} else {
$this->doUpdate($con);
}
$affectedRows += 1;
$this->resetModified();
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例5: postAdd
public function postAdd()
{
if (!$this->checkRoute()) {
return Redirect::route('index');
}
$title = 'Add An Author - ' . $this->site_name;
$input = Input::only('name', 'deck', 'website', 'donate_link', 'bio', 'slug');
$messages = ['unique' => 'The author already exists in the database.', 'url' => 'The :attribute field is not a valid URL.'];
$validator = Validator::make($input, ['name' => 'required|unique:authors,name', 'website' => 'url', 'donate_link' => 'url'], $messages);
if ($validator->fails()) {
return Redirect::action('AuthorController@getAdd')->withErrors($validator)->withInput();
}
$author = new Author();
$author->name = $input['name'];
$author->deck = $input['deck'];
$author->website = $input['website'];
$author->donate_link = $input['donate_link'];
$author->bio = $input['bio'];
if ($input['slug'] == '') {
$slug = Str::slug($input['name']);
} else {
$slug = $input['slug'];
}
$author->slug = $slug;
$author->last_ip = Request::getClientIp();
$success = $author->save();
if ($success) {
return View::make('authors.add', ['title' => $title, 'success' => true]);
}
return Redirect::action('AuthorController@getAdd')->withErrors(['message' => 'Unable to add author.'])->withInput();
}
示例6: runAuthorInsertion
function runAuthorInsertion($i)
{
$author = new Author();
$author->setFirstName('John' . $i);
$author->setLastName('Doe' . $i);
$author->save($this->con);
$this->authors[] = $author->getId();
}
示例7: testDelete
/** <tt>save && delete test</tt> */
public function testDelete()
{
$item = new Author();
$item->name = 'Andrei Cristescu';
$item->save();
$this->assertEqual($item->delete(), 1);
$this->assertEqual($item->delete(), 0);
}
示例8: authorInsertion
function authorInsertion($firstName, $lastName)
{
$author = new \Author();
$author->first_name = $firstName;
$author->last_name = $lastName;
$author->save();
return $author;
}
示例9: lol
public function lol()
{
$author = new Author();
$author->setFirstName('Jane' . rand(1, 100));
$author->setLastName('Austen' . rand(1, 100));
$author->save();
return $author;
}
示例10: post
/**
* Post name and email
*
* @param string $_name
* @param string $_email
*
* return array {@type Author}
*
*/
public function post($_name, $_email)
{
$auth = new Author();
$auth->name = $_name;
$auth->email = $_email;
$auth->save();
return $auth;
}
示例11: runAuthorInsertion
function runAuthorInsertion($i)
{
$author = new Author();
$author->first_name = 'John' . $i;
$author->last_name = 'Doe' . $i;
$author->save($this->con);
$this->authors[] = $author->id;
}
示例12: runAuthorInsertion
function runAuthorInsertion($i)
{
$author = new Author();
$author->firstName = 'John' . $i;
$author->lastName = 'Doe' . $i;
$author->save(false);
$this->authors[] = $author;
}
示例13: prepareData
/**
* prepareData
*/
public function prepareData()
{
for ($i = 0; $i < 10; $i++) {
$oAuthor = new Author();
$oAuthor->book_id = $i;
$oAuthor->name = "Author {$i}";
$oAuthor->save();
}
}
示例14: checkAuthor
function checkAuthor($author_name)
{
$new_author = null;
if (Author::findByName($author_name)) {
$new_author = Author::findByName($author_name);
} else {
$new_author = new Author($author_name);
$new_author->save();
}
return $new_author;
}
示例15: registerAction
public function registerAction()
{
if ($this->request->isPost()) {
$author = new Author();
$data = $this->request->getPost('data');
if (is_array($data) && count($data) > 0) {
$data['password'] = password_hash($data['password'], PASSWORD_BCRYPT);
$author->save($data);
return $this->response->redirect('index/login');
}
}
}