Commit 17ebc18f by Junaid Rahman pv

REST testings

parent aa0917c6
......@@ -85,6 +85,7 @@ class ThemeFileController extends \yii\web\Controller
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code;
if($model->fileContent){
file_put_contents($file, $model->fileContent);
Yii::$app->getSession()->setFlash('fileContentUpdated', [
'type' => 'success',
......@@ -97,6 +98,7 @@ class ThemeFileController extends \yii\web\Controller
'positonX' => 'right'
]);
}
}
return $this->render('editor', [
'model' => $model,
......
......@@ -41,12 +41,6 @@ $this->params['breadcrumbs'][] = $this->title;
</div>
</div>
</div>
<?php
$file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code;
$model->fileContent = file_get_contents($file);
?>
<div class="row">
<div class="col-md-6">
......@@ -58,6 +52,10 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="row">
<div class="col-md-11">
<?php
$file = yii::getAlias('@storage/private/theme-assets/') .$model->theme_code. '/' .$model->file_code;
$model->fileContent = file_get_contents($file);
?>
<?= $form->field($model, 'fileContent')->widget(
trntv\aceeditor\AceEditor::className(),
[
......
......@@ -78,7 +78,7 @@ class Theme extends \yii\db\ActiveRecord
{
return [
'id' => Yii::t('common', 'ID'),
'category_id' => Yii::t('common', 'Category ID'),
'category_id' => Yii::t('common', 'Category'),
'code' => Yii::t('common', 'Code'),
'slug' => Yii::t('common', 'Slug'),
'name' => Yii::t('common', 'Name'),
......
......@@ -57,7 +57,26 @@ $config = [
'loginUrl'=>['/user/sign-in/login'],
'enableAutoLogin' => true,
'as afterLogin' => 'common\behaviors\LoginTimestampBehavior'
]
],
'view' => [
'class' => 'yii\web\View',
'renderers' => [
'tpl' => [
'class' => 'yii\smarty\ViewRenderer',
//'cachePath' => '@runtime/Smarty/cache',
],
'twig' => [
'class' => 'yii\twig\ViewRenderer',
'cachePath' => '@runtime/Twig/cache',
// Array of twig options:
'options' => [
'auto_reload' => true,
],
'globals' => ['html' => '\yii\helpers\Html'],
'uses' => ['yii\bootstrap'],
],
],
],
]
];
......
<?php
namespace frontend\controllers;
use common\models\Category;
use common\models\CategoryFiles;
use common\models\Website;
use Yii;
use frontend\models\ContactForm;
use yii\web\Controller;
use yii\httpclient\Client;
use yii\db\Query;
use common\models\Theme;
use yii\twig;
use Twig_Loader_Filesystem;
use Twig_Environment;
/**
* Site controller
......@@ -35,20 +41,49 @@ class SiteController extends Controller
public function actionIndex()
{
$domain = $_SERVER['HTTP_HOST'];
$website = Website::find()->where(['domain_name' =>$domain])->one();
$website = Website::find()->where(['domain_name' => $domain])->one();
$businessId = $website->business_id;
if(isEmpty($businessId)){
$businessId = 3;
}
$themeId = $website->theme_id;
if (!$businessId) {
echo 'Business not found';
exit();
} else {
$theme = Theme::find()->where(['id' => $themeId])->one();
if (!$theme) {
echo 'theme not found';
exit();
} else {
$category = Category::find()->where(['id' => $theme->category_id])->one();
if (!$category) {
echo 'category not found';
exit();
} else {
$categoryFiles = CategoryFiles::find()->where(['category_id' => $category->id])->all();
foreach ($categoryFiles as $file) {
$path = yii::getAlias('@storage/private/theme-assets/') . $theme->code . '/';
$loader = new Twig_Loader_Filesystem($path);
$twig = new Twig_Environment($loader);
$client = new Client();
$response = $client->createRequest()
->setMethod('get')
->setUrl('http://libromi.com/api/v1/business/view')
->setData(['id' => 2])
->setUrl('http://libromi.com/api/v1/business/search')
->setData(['keyword' => 'nrs'])
->send();
$data = $response->isOk ? $response->data : [];
return $this->render('index', ['data' => $data]);
// echo $data['items'][0]['name'];
// echo $data['items'][0]['email'];
echo $twig->render('home',
array('name' => $data['items'][0]['name'], 'email' => $data['items'][0]['email']));
}
}
}
}
// return $this->render('index', ['data' => $data]);
}
public function actionContact()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment