Commit 17ebc18f by Junaid Rahman pv

REST testings

parent aa0917c6
...@@ -85,6 +85,7 @@ class ThemeFileController extends \yii\web\Controller ...@@ -85,6 +85,7 @@ class ThemeFileController extends \yii\web\Controller
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code; $file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code;
if($model->fileContent){
file_put_contents($file, $model->fileContent); file_put_contents($file, $model->fileContent);
Yii::$app->getSession()->setFlash('fileContentUpdated', [ Yii::$app->getSession()->setFlash('fileContentUpdated', [
'type' => 'success', 'type' => 'success',
...@@ -97,6 +98,7 @@ class ThemeFileController extends \yii\web\Controller ...@@ -97,6 +98,7 @@ class ThemeFileController extends \yii\web\Controller
'positonX' => 'right' 'positonX' => 'right'
]); ]);
} }
}
return $this->render('editor', [ return $this->render('editor', [
'model' => $model, 'model' => $model,
......
...@@ -41,12 +41,6 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -41,12 +41,6 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
</div> </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="row">
<div class="col-md-6"> <div class="col-md-6">
...@@ -58,6 +52,10 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -58,6 +52,10 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="row"> <div class="row">
<div class="col-md-11"> <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( <?= $form->field($model, 'fileContent')->widget(
trntv\aceeditor\AceEditor::className(), trntv\aceeditor\AceEditor::className(),
[ [
......
...@@ -78,7 +78,7 @@ class Theme extends \yii\db\ActiveRecord ...@@ -78,7 +78,7 @@ class Theme extends \yii\db\ActiveRecord
{ {
return [ return [
'id' => Yii::t('common', 'ID'), 'id' => Yii::t('common', 'ID'),
'category_id' => Yii::t('common', 'Category ID'), 'category_id' => Yii::t('common', 'Category'),
'code' => Yii::t('common', 'Code'), 'code' => Yii::t('common', 'Code'),
'slug' => Yii::t('common', 'Slug'), 'slug' => Yii::t('common', 'Slug'),
'name' => Yii::t('common', 'Name'), 'name' => Yii::t('common', 'Name'),
......
...@@ -51,7 +51,8 @@ ...@@ -51,7 +51,8 @@
"symfony/process": "^3.0", "symfony/process": "^3.0",
"yiisoft/yii2-httpclient": "*", "yiisoft/yii2-httpclient": "*",
"wbraganca/yii2-dynamicform": "*", "wbraganca/yii2-dynamicform": "*",
"kartik-v/yii2-widget-growl": "*" "kartik-v/yii2-widget-growl": "*",
"yiisoft/yii2-twig": "^2.0"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "^2.0.0", "yiisoft/yii2-debug": "^2.0.0",
......
...@@ -57,7 +57,26 @@ $config = [ ...@@ -57,7 +57,26 @@ $config = [
'loginUrl'=>['/user/sign-in/login'], 'loginUrl'=>['/user/sign-in/login'],
'enableAutoLogin' => true, 'enableAutoLogin' => true,
'as afterLogin' => 'common\behaviors\LoginTimestampBehavior' '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 <?php
namespace frontend\controllers; namespace frontend\controllers;
use common\models\Category;
use common\models\CategoryFiles;
use common\models\Website; use common\models\Website;
use Yii; use Yii;
use frontend\models\ContactForm; use frontend\models\ContactForm;
use yii\web\Controller; use yii\web\Controller;
use yii\httpclient\Client; use yii\httpclient\Client;
use yii\db\Query; use yii\db\Query;
use common\models\Theme;
use yii\twig;
use Twig_Loader_Filesystem;
use Twig_Environment;
/** /**
* Site controller * Site controller
...@@ -35,20 +41,49 @@ class SiteController extends Controller ...@@ -35,20 +41,49 @@ class SiteController extends Controller
public function actionIndex() public function actionIndex()
{ {
$domain = $_SERVER['HTTP_HOST']; $domain = $_SERVER['HTTP_HOST'];
$website = Website::find()->where(['domain_name' =>$domain])->one(); $website = Website::find()->where(['domain_name' => $domain])->one();
$businessId = $website->business_id; $businessId = $website->business_id;
if(isEmpty($businessId)){ $themeId = $website->theme_id;
$businessId = 3; 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(); $client = new Client();
$response = $client->createRequest() $response = $client->createRequest()
->setMethod('get') ->setMethod('get')
->setUrl('http://libromi.com/api/v1/business/view') ->setUrl('http://libromi.com/api/v1/business/search')
->setData(['id' => 2]) ->setData(['keyword' => 'nrs'])
->send(); ->send();
$data = $response->isOk ? $response->data : []; $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() 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