public function init() { $this->arrSystem = System::model()->find(); $this->arrInfo = Informations::model()->find(); $criteria = new CDBCriteria(); $criteria->addCondition("id!=1"); $this->arrCategoryNew = CategoriesNews::model()->findAll($criteria); }
public function actionIndex($id = 0) { $model = Informations::model()->findByPK($id); if (empty($model)) { $model = new Informations(); } $flag = 0; if (!empty($_POST['Informations'])) { if (!empty(CUploadedFile::getInstance($model, 'image')->name)) { $image_old = $model->attributes['image']; $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image_old); if (file_exists($path) && !empty($image_old)) { unlink($path); } $model->attributes = $_POST['Informations']; $model->image = CUploadedFile::getInstance($model, 'image'); $image = $model->image; $imageType = explode('.', $model->image->name); $imageType = $imageType[count($imageType) - 1]; $imageName = md5(uniqid()) . '.' . $imageType; $model->image = $imageName; $images_path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName; $flag = 1; } else { $arr = $_POST['Informations']; $model->attributes = $arr; } $model->created = time(); $model->alias = alias($_POST['Informations']['name']); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Cập nhật thành công.')); if ($flag == 1) { $image->saveAs($images_path); } if ($id != 0) { $this->redirect(PIUrl::createUrl('/admin/informations/', array('id' => $id))); } else { $this->redirect(PIUrl::createUrl('/admin/informations/')); } } } $this->render('index', array('model' => $model)); }
<?php // Namespaces //MODELS $informations_models = new Informations($app['db']); //ROUTES //HOME $app->get('/', function () use($app) { return $app['twig']->render('home.html.twig'); })->bind('home'); //BEFORE CATEGORY $app->get('/information/{id}', function ($id) use($app, $informations_models) { $data = array('all_informations' => $informations_models->get_all($id)); return $app['twig']->render('before_category.html.twig', $data); })->bind('before_category'); //ERROR $app->error(function (\Exception $e, $code) { if (404 == $code) { return 'error'; } });