<?php
use Yii;
use backend\models\Book;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\db\Query;

class BookController extends Controller
{
    public function actionshowBook()
    {
        $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';

        if($id == 0 || $id == NULL)
        {
            $sql = 'SELECT * FROM book';
            $book = Book::findBySql($sql)->all();
        }
        else{
            $book = Book::findAll('id ='.$id);
        }
        $path = Yii::$app->basePath ;
        $data=array();
        foreach ($book as $item)
        {
            $data[] = array(
                'id' => $id,
                'title'=> $item->title,
                'author' =>$item->author,
                'publisher'=> $item->publisher,
                'image' => isset($item->image)?$path.'/web/images/book'.$item->image:'',
				'type'=> $item->type,
				'attachment'=>isset($item->attachment)?$path.'/web/attachment/book'.$item->attachment:''
            );
        }
        echo json_encode(array('status'=>1,'data'=>$data,JSON_PRETTY_PRINT);

    }

}
