public function actionIndex() { // Загружаем страницу "Наши работы" Yii::import("application.modules.page.models.Page"); $page = Page::model()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC')))->findByPath("portfolio"); $this->render('index', array('page' => $page)); }
protected function renderContent() { $model = new Page(); //If it has guid, it means this is a translated version $guid = isset($_GET['guid']) ? strtolower(trim($_GET['guid'])) : ''; //List of language that should exclude not to translate $lang_exclude = array(); //List of translated versions $versions = array(); // If the guid is not empty, it means we are creating a translated version of a content // We will exclude the translated language and include the name of the translated content to $versions if ($guid != '') { $page_object = Page::model()->findAll('guid=:gid', array(':gid' => $guid)); if (count($page_object) > 0) { $langs = GxcHelpers::getAvailableLanguages(); foreach ($page_object as $obj) { $lang_exclude[] = $obj->lang; $versions[] = $obj->name . ' - ' . $langs[$obj->lang]['name']; } } $model->guid = $guid; } // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'page-form') { echo CActiveForm::validate($model); Yii::app()->end(); } //Define Blocks in Regions $regions_blocks = array(); // collect user input data if (isset($_POST['Page'])) { $regions_blocks = isset($_POST['Page']['regions']) ? $_POST['Page']['regions'] : array(); $model->attributes = $_POST['Page']; if ($model->save()) { if (!empty($regions_blocks)) { //Delete All Page Block Before PageBlock::model()->deleteAll('page_id = :id', array(':id' => $model->page_id)); foreach ($regions_blocks as $key => $blocks) { $order = 1; for ($i = 0; $i < count($blocks['id']); $i++) { $block = $blocks['id'][$i]; $temp_page_block = new PageBlock(); $temp_page_block->page_id = $model->page_id; $temp_page_block->block_id = $block; $temp_page_block->region = $key; $temp_page_block->block_order = $order; $temp_page_block->status = $blocks['status'][$i]; $temp_page_block->save(); $order++; } } } //Start to save the Page Block user()->setFlash('success', t('cms', 'Create new Page Successfully!')); $model = new Page(); Yii::app()->controller->redirect(array('create')); } } $this->render('cmswidgets.views.page.page_form_widget', array('model' => $model, 'lang_exclude' => $lang_exclude, 'versions' => $versions, 'regions_blocks' => $regions_blocks)); }
public function loadModel($id) { if (($model = Page::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function run() { $ids = Yii::app()->request->getParam('id'); $command = Yii::app()->request->getParam('command'); empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select')); if (!is_array($ids)) { $ids = array($ids); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $ids); switch ($command) { case 'delete': //删除 Page::model()->deleteAll($criteria); break; case 'show': //显示 Page::model()->updateAll(['status' => 'Y'], $criteria); break; case 'hidden': //隐藏 Page::model()->updateAll(['status' => 'N'], $criteria); break; default: $this->controller->message('error', Yii::t('admin', 'Error Operation')); } $this->controller->message('success', Yii::t('admin', 'Batch Operate Success')); }
/** * Set paths for all models. * * @return void */ public function actionPaths() { $models = Page::model()->resetScope()->findAll(); foreach ($models as $model) { $model->save(true, array('path')); } }
public function parsePosts() { $content = $this->getContent($this->web_url); if (!$content) { return; } $doc = new DOMDocument(); @$doc->loadHTML($content); $path = new DOMXPath($doc); $links = $path->query('//div[@class="newsItem"]/h2/a'); $images = $path->query('//div[@class="newsItem"]/a/img'); foreach ($links as $i => $link) { $href = $source_url = $this->prepareHref($link->getAttribute('href')); $page = Page::model()->findByAttributes(array('source' => $this->source, 'source_url' => $source_url)); if ($page) { $this->log("Пост #{$page->id} уже был спарсен, пропускаем"); continue; } $image = $images->item($i); if ($image) { $image = $this->web_url . $image->getAttribute('src'); } $this->parsePost($this->web_url . $href, $image, $source_url); } }
public function loadModel($id) { if (($model = Page::model()->findByPk($id)) === null) { throw new CHttpException(404, Yii::t('PageModule.page', 'Page was not found!')); } return $model; }
/** * FAQ */ public function actionFaq() { // Загружаем страницу "FAQ" Yii::import("application.modules.page.models.Page"); $page = Page::model()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC')))->findByPath("faq"); // Список групп $groups = FaqGroup::model()->published()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC'), 'questions' => array('scopes' => array('answered', 'faq'), 'order' => 'questions.sort ASC')))->findAll(array('order' => 't.sort ASC')); /* $dataProvider = new CActiveDataProvider('Feedback', array('criteria' => array( 'condition' => 'type_id = :type_id AND (status = :sended OR status = :finished)', 'params' => array( ':type_id' => $type->id, ':sended' => Feedback::STATUS_ANSWER_SENDED, ':finished' => Feedback::STATUS_FINISHED, ), 'order' => 't.sort ASC', ))); * */ $type = DictionaryData::model()->findByCode('feedback-faq'); if (!$type) { throw new CHttpException(404); } $form = $this->_processForm($type); $this->render('faq', array('model' => $form, 'page' => $page, 'groups' => $groups)); }
/** * Возвращает объект запрашиваемой страницы * * @return Page модель страницы */ public function getModel() { if ($this->_model === null) { if (!isset($_GET['pageId'])) { $lang = Yii::app()->language; if (!empty($_GET['alias'])) { $page = Page::model()->find("`{$lang}_alias` = :alias", array(':alias' => $_GET['alias'])); if ($page && (!Yii::app()->params['strictFind'] || $page[$lang . '_alias'] == $_GET['alias'])) { $_GET['pageId'] = $page->id; $this->_model = $page; } } elseif (!empty($_GET['url'])) { $page = Page::model()->find("`{$lang}_url` = :url", array(':url' => '/' . $_GET['url'])); if ($page && (!Yii::app()->params['strictFind'] || $page[$lang . '_url'] == '/' . $_GET['url'])) { $_GET['pageId'] = $page->id; $this->_model = $page; } } else { $_GET['pageId'] = 1; $this->_model = Page::model()->findByPk(1); } } else { if (isset($_GET['pageId'])) { $this->_model = Page::model()->findbyPk($_GET['pageId']); } if ($this->_model && $this->_model->language) { Yii::app()->language = $this->_model->language; } } } return $this->_model; }
public function run() { $pages = Page::model()->getRecentPages(); ?> <ul> <?php foreach ($pages as $page) { ?> <li> <?php $title = CHtml::encode($page->title); echo CHtml::link($title, $page->url); ?> </li> <?php } ?> <?php if (!$pages) { echo Yii::t('app', 'Sorry, no recent pages!'); } ?> </ul> <?php parent::run(); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $model = Page::model()->find('name=:name', array(':name' => 'home_page')); $this->render('index', array('model' => $model)); }
public function run() { // 主菜单 $menuId = Yii::app()->controller->menuId; $rootId = Page::model()->getRootIdByPk($menuId); if ($rootId == false) { $rootId = $menuId; } $items = array(); $criteria = new CDbCriteria(); $criteria->compare('parent_id', '0'); $criteria->compare('is_indexable', '1'); $criteria->order = 'sort_order ASC'; $pages = Page::model()->localized()->findAll($criteria); foreach ($pages as $i => $page) { $items[$i] = array('template' => '{menu}', 'label' => $page->title, 'url' => $page->getPermalink()); if ($i == 0) { $items[$i]['itemOptions'] = array('class' => $page->primaryKey == $rootId ? 'line active' : 'line'); } else { if ($page->primaryKey == $rootId) { $items[$i]['itemOptions'] = array('class' => 'active'); } } } if ($menuId == 0) { $items = array_merge(array(array('label' => Yii::t('common', '首页'), 'url' => array('site/index'), 'itemOptions' => array('class' => 'cur'))), $items); } else { $items = array_merge(array(array('label' => Yii::t('common', '首页'), 'url' => array('site/index'))), $items); } $this->render('menu', array('items' => $items)); }
/** * Index action: * * @return void */ public function actionIndex() { $module = Yii::app()->getModule('homepage'); $view = $data = null; if ($module->mode == HomepageModule::MODE_PAGE) { $target = Page::model()->findByPk($module->target); if (null === $target) { throw new CHttpException('404', Yii::t('HomepageModule.page', 'Page was not found')); } $page = Page::model()->published()->find('slug = :slug AND lang = :lang', [':slug' => $target->slug, ':lang' => Yii::app()->getLanguage()]); $page = $page ?: $target; $view = $page->view ?: 'page'; $data = ['page' => $page]; } if ($module->mode == HomepageModule::MODE_POSTS) { $view = 'posts'; $dataProvider = new CActiveDataProvider('Post', ['criteria' => new CDbCriteria(['condition' => 't.status = :status', 'params' => [':status' => Post::STATUS_PUBLISHED], 'limit' => $module->limit, 'order' => 't.publish_time DESC', 'with' => ['createUser', 'blog', 'commentsCount']])]); $data = ['dataProvider' => $dataProvider]; } if ($module->mode == HomepageModule::MODE_STORE) { $view = 'store'; Yii::import('application.modules.store.components.ProductRepository'); $data = ['dataProvider' => (new ProductRepository())->getListForIndexPage()]; } $this->render($view, $data); }
/** * Generate sitemap. */ public function actionSitemapxml() { $posts = Post::model()->findAll(array('order' => 'createTime DESC', 'condition' => 'status=' . Post::STATUS_PUBLISHED)); $pages = Page::model()->findAll(array('order' => 'createTime DESC', 'condition' => 'status=' . Page::STATUS_PUBLISHED)); header('Content-Type: application/xml'); $this->renderPartial('../site/sitemapxml', array('posts' => $posts, 'pages' => $pages)); }
/** * Create or update new page * @param boolean $new */ public function actionUpdate($new = false) { if ($new === true) { $model = new Page(); } else { $model = Page::model()->cache($this->cacheTime)->language(Yii::app()->language->active)->findByPk($_GET['id']); } $this->breadcrumbs = array(Yii::t('PagesModule.default', 'MODULE_NAME') => $this->createUrl('index'), $model->isNewRecord ? $model->t('PAGE_TITLE', 0) : CHtml::encode($model->title)); $this->pageName = $model->isNewRecord ? $model->t('PAGE_TITLE', 0) : $model->t('PAGE_TITLE', 1); if (!$model) { throw new CHttpException(404); } if (Yii::app()->request->isPostRequest) { $model->attributes = $_POST['Page']; if ($model->validate()) { $model->save(); if ($model->in_menu == 1) { $isset = MenuModel::model()->findByAttributes(array('url' => '/page/' . $model->seo_alias)); if (!isset($isset)) { $menu = new MenuModel(); $menu->label = $model->title; $menu->url = '/page/' . $model->seo_alias; if ($menu->validate()) { $menu->save(false, false); } } } $this->redirect(array('index')); } } $this->render('update', array('model' => $model)); }
public function afterUninstall() { //Удаляем таблицу модуля Yii::app()->db->createCommand()->dropTable(Page::model()->tableName()); Yii::app()->db->createCommand()->dropTable(PageTranslate::model()->tableName()); return parent::afterUninstall(); }
public function actionIndex($alias = '') { // Определяем, выбрана или нет категория $category = null; if (!empty($alias)) { // Если выбрана категория $category = PublicationCategory::model()->published()->findByAlias($alias); if (is_null($category)) { throw new CHttpException(404); } $page = $category; $this->currentCategory = $category; } else { // Загружаем страницу "Новости" Yii::import("application.modules.page.PageModule"); Yii::import("application.modules.page.models.Page"); $page = Page::model()->findByPath("publications"); } // Показываем только публичные новости $model = new Publication('user_search'); $model->unsetAttributes(); // Категория if (!empty($category)) { $model->search_category = $category->id; } $dataProvider = $model->user_search(); $this->render('index', ['dataProvider' => $dataProvider, 'page' => $page, 'currentCategory' => $category]); }
public function init() { parent::init(); $ids = explode(',', $this->params['page']->path); $pages = Page::model()->findAll(array('condition' => 't.`id` IN (' . $this->params['page']->path . ')', 'order' => '`path` DESC')); $parents = array(); foreach ($pages as $p) { $parents[$p->id] = $p; } unset($pages); $links = array(); foreach ($ids as $id) { if ($id == 0 || $id == 1) { continue; } $links[$parents[$id]->title] = array('view/index', 'pageId' => $parents[$id]->id, 'alias' => $parents[$id]->alias, 'url' => $parents[$id]->url); } if ($this->params['page']->id != 1) { $links[] = $this->params['page']->title; } else { $links[] = ''; } $this->params['links'] = $links; $this->params['separator'] = $this->params['content']->separator ? $this->params['content']->separator : self::DEFAULT_SEPARATOR; $this->params['homeLink'] = $parents ? CHtml::link($parents[1]->title, array('view/index', 'pageId' => $parents[1]->id, 'alias' => $parents[1]->alias, 'url' => $parents[1]->url)) : $this->params['page']->title; }
public function actionOrder() { $name = Yii::app()->request->getParam('name'); $phone = Yii::app()->request->getParam('phone'); $comment = Yii::app()->request->getParam('comment'); header('Content-Type: application/json'); if ($name && $phone) { if (($v1 = Yii::app()->session->get('verifyCode')) && ($v2 = Yii::app()->request->getParam('verifyCode')) && $v1 == $v2) { $message = "Имя: " . $name . "\n"; $message .= "Телефон: " . $phone . "\n"; if ($comment) { $message .= "Комментарий: \n" . $comment . "\n"; } $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=UTF-8"; $headers[] = "From: Cndiesel.ru <*****@*****.**>"; $email = Page::model()->findByAttributes(array('name' => 'Param: email для отправки заказов')); if (mail($email->text, 'Новый заказ на cndiesel.ru', $message, implode("\r\n", $headers))) { echo json_encode(array('result' => 0, 'code' => 'ok')); } else { echo json_encode(array('result' => 1, 'code' => 'send_mail_error')); } } else { echo json_encode(array('result' => 1, 'code' => 'captcha_error')); } } else { echo json_encode(array('result' => 1, 'code' => 'invalid_args')); } }
/** * @param Event $event */ public static function onGenerate(Event $event) { $generator = $event->getGenerator(); $provider = new CActiveDataProvider(Page::model()->published()->public()); foreach (new CDataProviderIterator($provider) as $item) { $generator->addItem(Yii::app()->createAbsoluteUrl('/page/page/view', ['slug' => $item->slug]), strtotime($item->update_time), SitemapHelper::FREQUENCY_WEEKLY, 0.5); } }
public function getBaseModel() { if ($this->baseModel) { return $this->baseModel; } $commentedModel = Page::model(); return $commentedModel->findByPk($this->pageId); }
public function getAllPagesForAutocomplete() { $allpages = array(); foreach (Page::model()->findAll() as $model) { $allpages[] = array('name' => $model->meta_title, 'label' => $model->meta_title, 'id' => $model->key); } return $allpages; }
public function actionPage_cms($slug) { $page = Page::model()->findByAttributes(array('slug' => $slug)); if ($page === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $this->render('page', array('page' => $page)); }
private function loadPage($id, $slug) { $model = Page::model()->findByAttributes(array('ID' => (int) $id, 'post_link' => $slug)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * * @param integer $id the ID of the model to be loaded * * @throws CHttpException * * @return Page */ public function loadModel($id) { $model = Page::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Отображение главной страницы * * @return void */ public function actionIndex() { // Загружаем страницу "Отзывы" Yii::import("application.modules.page.models.Page"); $page = Page::model()->with(array('slides' => array('scopes' => 'published')))->findByPath("index"); $this->layout = 'index'; $this->render('index', array('page' => $page)); }
public function actionContact() { $page = Page::model()->find('id=:id AND status=:status', array(':id' => 'contact', ':status' => 'Y')); if (!$page) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); } $this->menu_tab = 'contact'; $this->render('contact', array('contact' => $page, 'menu_tab' => 'contact')); }
/** * Display page by url. * Example url: /page/some-page-url * @param string $url page url */ public function actionView($url) { $model = Page::model()->published()->withUrl($url)->find(array('limit' => 1)); if (!$model) { throw new CHttpException(404, Yii::t('PagesModule.core', 'Страница не найдена.')); } $view = $this->setDesign($model, 'view'); $this->render($view, array('model' => $model)); }
/** * @return array */ public function getTargets() { if ($this->mode == self::MODE_POSTS) { return CHtml::listData(Post::model()->public()->published()->findAll(), 'id', 'title'); } if ($this->mode == self::MODE_PAGE) { return CHtml::listData(Page::model()->public()->published()->findAll(), 'id', 'title'); } return []; }
public function actionIndex() { // Загружаем страницу "Коллекции" Yii::import("application.modules.page.models.Page"); $page = Page::model()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC')))->findByPath("collections"); // Список коллекций $collections = new Collection('user_search'); $dataProvider = new CActiveDataProvider($collections->published()->with(array('series' => array('scopes' => 'published', 'order' => 'series.sort ASC'))), array('pagination' => false, 'sort' => array('defaultOrder' => 't.sort ASC'))); $this->render('index', array('dataProvider' => $dataProvider, 'page' => $page)); }