本文整理汇总了PHP中Author::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::find方法的具体用法?PHP Author::find怎么用?PHP Author::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postEdit
public function postEdit($id)
{
if (!$this->checkRoute()) {
return Redirect::route('index');
}
$title = 'Edit An Author - ' . $this->site_name;
$author = Author::find($id);
$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,' . $author->id, 'website' => 'url', 'donate_link' => 'url'], $messages);
if ($validator->fails()) {
return Redirect::action('AuthorController@getEdit', [$id])->withErrors($validator)->withInput();
}
$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'] == '' || $input['slug'] == $author->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.edit', ['title' => $title, 'success' => true, 'author' => $author]);
}
return Redirect::action('AuthorController@getEdit', [$id])->withErrors(['message' => 'Unable to add author.'])->withInput();
}
示例2: get
/**
* Get one Author
*
* return array {@type Author}
*
* @view authorDetailView
*
*/
public function get($id)
{
if (!($feedback = Author::find($id))) {
throw new RestException(404, 'feedback not found');
}
return $feedback;
}
示例3: author
public function author($id)
{
$author = Author::find($id);
$books = DB::table('katalog')->join('author_katalog', 'katalog.id', '=', 'author_katalog.idkatalog')->where('author_katalog.author', '=', $id)->get(array('katalog.title', 'katalog.release', 'katalog.id', 'katalog.category'));
$comment = Comment::where('id_obj', '=', $author->id)->where('cat_comment', '=', 2)->get();
$act = 'person';
return View::make('front.author', compact('author', 'books', 'comment', 'act'));
}
示例4: test_find
function test_find()
{
$name = "Jerry Garcia";
$test_author = new Author($name);
$test_author->save();
$name2 = "Frank Sinatra";
$test_author2 = new Author($name2);
$test_author2->save();
$result = Author::find($test_author->getId());
$this->assertEquals($test_author, $result);
}
示例5: testFind
function testFind()
{
$name = "Stephen King";
$test_author = new Author($name);
$test_author->save();
$name2 = "Neal Stephenson";
$test_author2 = new Author($name2);
$test_author2->save();
$result = Author::find($test_author->getId());
$this->assertEquals($result, $test_author);
}
示例6: testSaveSelect
/** <tt>find a unexistent record</tt> */
public function testSaveSelect()
{
$item = new Author();
$item->name = 'Mihai Eminescu';
$item->save();
try {
$items = Author::find(100);
$this->fail('Should throw an exception!');
} catch (Exception $ex) {
$this->assertIsA($ex, 'RecordNotFoundException');
}
$item->delete();
}
示例7: testFind
function testFind()
{
//Arrange
$id = null;
$name = "Lemony Snicket";
$test_author = new Author($id, $name);
$test_author->save();
$name2 = "J.R.R. Tolkien";
$test_author2 = new Author($id, $name2);
$test_author2->save();
//Act
$result = Author::find($test_author->getId());
//Assert
$this->assertEquals($test_author, $result);
}
示例8: testFind
function testFind()
{
//Arrange
$name = "JK Rowling";
$id = 1;
$test_author = new Author($name, $id);
$test_author->save();
$name2 = "George RR Martin";
$id2 = 2;
$test_author2 = new Author($name, $id);
$test_author2->save();
//Act
$result = Author::find($test_author2->getId());
//Assert
$this->assertEquals($test_author2, $result);
}
示例9: test_find_by_datetime
public function test_find_by_datetime()
{
$now = new DateTime();
$arnow = new ActiveRecord\DateTime();
$arnow->setTimestamp($now->getTimestamp());
Author::find(1)->update_attribute('created_at', $now);
$this->assert_not_null(Author::find_by_created_at($now));
$this->assert_not_null(Author::find_by_created_at($arnow));
}
示例10: testFind
function testFind()
{
//Arrange
$author_name = "Frank Herbert";
$id = null;
$test_author = new Author($author_name, $id);
$test_author->save();
$author_name2 = "Neal Stephenson";
$id2 = null;
$test_author2 = new Author($author_name2, $id2);
$test_author2->save();
//Act
$result = Author::find($test_author->getId());
//Assert
$this->assertEquals($test_author, $result);
}
示例11: array
$new_book->save();
return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->post("/authors", function () use($app) {
$new_author = new Author($_POST['name']);
$new_author->save();
return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
});
$app->post("/patrons", function () use($app) {
$new_patron = new Patron($_POST['name']);
$new_patron->save();
return $app['twig']->render('patrons.html.twig', array('patrons' => Patron::getAll()));
});
$app->post("/add_author", function () use($app) {
$book = Book::find($_POST['book_id']);
$author = Author::find($_POST['author_id']);
$book->addAuthor($author);
return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll()));
});
$app->post("/add_book", function () use($app) {
$book = Book::find($_POST['book_id']);
$author = Author::find($_POST['author_id']);
$author->addBook($book);
return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $author->getBooks(), 'all_books' => Book::getAll()));
});
$app->post("/add_copy", function () use($app) {
$book = Book::find($_POST['book_id']);
$book->addCopy();
return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll()));
});
return $app;
示例12: testCreationOfEmptyRecord
/**
* testCreationOfEmptyRecord method
*
* @return void
*/
public function testCreationOfEmptyRecord()
{
$this->loadFixtures('Author');
$TestModel = new Author();
$this->assertEquals(4, $TestModel->find('count'));
$TestModel->deleteAll(true, false, false);
$this->assertEquals(0, $TestModel->find('count'));
$result = $TestModel->save();
$this->assertTrue(isset($result['Author']['created']));
$this->assertTrue(isset($result['Author']['updated']));
$this->assertEquals(1, $TestModel->find('count'));
}
示例13: testValidatesWithModelsAndSaveAllWithoutId
/**
* test that saveAll and with models at initial insert (no id has set yet)
* with validation interact well
*
* @return void
*/
public function testValidatesWithModelsAndSaveAllWithoutId()
{
$this->loadFixtures('Post', 'Author');
$data = array('Author' => array('name' => 'Foo Bar'), 'Post' => array(array('title' => 'Hello'), array('title' => 'World')));
$Author = new Author();
$Post = $Author->Post;
$Post->validate = array('author_id' => array('rule' => 'numeric'));
$Author->create();
$result = $Author->saveAll($data, array('validate' => 'only'));
$this->assertTrue($result);
$result = $Author->validateAssociated($data);
$this->assertTrue($result);
$this->assertTrue($result);
$Author->create();
$result = $Author->saveAll($data, array('validate' => 'first'));
$this->assertTrue($result);
$this->assertNotNull($Author->id);
$id = $Author->id;
$count = $Author->find('count', array('conditions' => array('Author.id' => $id)));
$this->assertSame(1, $count);
$count = $Post->find('count', array('conditions' => array('Post.author_id' => $id)));
$this->assertEquals($count, count($data['Post']));
}
示例14: testFindByDatetime
public function testFindByDatetime()
{
$now = new DateTime();
$arnow = new ActiveRecord\DateTime();
$arnow->setTimestamp($now->getTimestamp());
Author::find(1)->updateAttribute('created_at', $now);
$this->assertNotNull(Author::findByCreatedAt($now));
$this->assertNotNull(Author::findByCreatedAt($arnow));
}
示例15: testSetDateFlagsDirtyWithPhpDatetime
public function testSetDateFlagsDirtyWithPhpDatetime()
{
$author = Author::create(array('some_date' => new \DateTime()));
$author = Author::find($author->id);
$author->some_date->setDate(2010, 1, 1);
$this->assertHasKeys('some_date', $author->dirtyAttributes());
}