public function handleCreate() { $data = Input::all(); $rules = array('title' => 'required', 'route' => 'required|Unique:pages'); // Create a new validator instance. $validator = Validator::make($data, $rules); if ($validator->passes()) { $user_id = Auth::id(); $page = new Page(); $page->title = Input::get('title'); $page->route = Input::get('route'); $page->breadcumbs = Input::get('breadcumb'); $page->keywords = Input::get('keywords'); $page->description = Input::get('description'); $page->content = Input::get('content'); $page->tags = Input::get('tags'); $page->layout_id = Input::get('layout'); $page->status_id = Input::get('status'); $page->valid_until = Input::get('valid_until'); $page->created_by_id = $user_id; $page->updated_by_id = $user_id; if (Input::get('save')) { $page->save(); return Redirect::action('AdminPageController@index')->with('flash_edit_success', 'Hurray!You have created a Page'); } elseif (Input::get('continue')) { $page->save(); return Redirect::action('AdminPageController@edit', $page->id)->with('flash_edit_success', 'Hurray!Your updated information are saved,You can continue work...'); } else { return Redirect::action('AdminPageController@index')->with('flash_dlt_success', 'OH!Sorry! I can not make a Page in this time'); } } else { return Redirect::back()->withInput()->withErrors($validator); } }
/** * 单页添加 */ public function actionCreate() { $model = new Page(); if (isset($_POST['Page'])) { $model->attributes = $_POST['Page']; if ($_FILES['attach']['error'] == UPLOAD_ERR_OK) { $upload = new Uploader(); $upload->_thumb_width = '200'; $upload->_thumb_height = '180'; $upload->uploadFile($_FILES['attach'], true); if ($upload->_error) { $upload->deleteFile($upload->_file_name); $upload->deleteFile($upload->_thumb_name); $this->message('error', Yii::t('admin', $upload->_error)); return; } $model->attach_file = $upload->_file_name; $model->attach_thumb = $upload->_thumb_name; } $model->create_time = time(); if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
public function test_belongs_to() { MemoryStore::flush(); Page::delete_all(); User::delete_all(); $user = new User(); $user->email = "*****@*****.**"; $user->first_name = "Ben"; $user->last_name = "Copsey"; $user->password = "******"; $user->accepted_terms_and_conditions = true; $user->registration_date = new Date(); $user->first_name = "Ben"; $user->save(); $page1 = new Page(); $page1->title = "This is page 1"; $page1->last_modified = new Date(); $page1->body = "This is the content"; $page1->url = "page-1"; $page1->author = $user; $page1->save(); FuzzyTest::assert_equal($page1->author_id, $user->id, "Author not set correctly"); $user->delete(); $page = Page::find_by_url('page-1'); FuzzyTest::assert_true(isset($page), "Page deleted when it should have been preserved"); FuzzyTest::assert_equal($page->author_id, 0, "Page deleted when it should have been preserved"); $user->save(); $page->author = $user; $page->save(); $matches = $user->pages; FuzzyTest::assert_equal(count($matches), 1, "Page count should be 1"); }
function save($request) { $page = new Page(); $page->serializeArray("Page", $request['page']); $return = $page->save(); echo json_encode($return); }
public function createEdit() { $pageId = Input::get('pageId', null); $pageData = Input::get('page', array()); try { if ($pageId || !empty($pageData['id'])) { //die(var_dump($pageId)); $page = Page::findOrFail($pageId ? $pageId : $pageData['id']); } else { $page = new Page(); } } catch (ModelNotFoundException $e) { return Response::json(array('error' => 1, 'message' => $e->getMessage())); } if (Request::ajax() && Request::isMethod('post')) { //Form submitted- Create the page //$keys = ['topic', 'description', 'pageContent', 'image', 'questions', 'results', 'ogImages']; foreach ($pageData as $key => $val) { $page->{$key} = is_array($pageData[$key]) ? json_encode($pageData[$key]) : $pageData[$key]; } //var_dump($page); $page->save(); return Response::json(array('success' => 1, 'page' => $page)); } else { $pageSchema = new \Schemas\PageSchema(); return View::make('admin/pages/create')->with(array('pageSchema' => $pageSchema->getSchema(), 'pageData' => Page::decodePageJson($page), 'editingMode' => $pageId ? true : false, 'creationMode' => $pageId ? false : true)); } }
public function add() { if (Request::isMethod('post')) { $rules = array('title' => 'required|min:4', 'link' => "required|unique:{$this->table}", 'content' => 'required|min:50', 'meta_description' => 'required|min:20', 'meta_keywords' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to("admin/{$this->name}/{$this->action}")->withErrors($validator)->withInput(Input::except('')); } else { $table = new Page(); $table->title = Input::get('title'); $table->link = Input::get('link'); $table->user_id = Auth::user()->id; $table->content = Input::get('content'); $table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title; $table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : $table->description; $table->meta_keywords = Input::get('meta_keywords'); $table->published_at = Page::toDate(Input::get('published_at')); $table->active = Input::get('active', 0); if ($table->save()) { $name = trans("name.{$this->name}"); return Redirect::to("admin/{$this->name}")->with('success', trans("message.{$this->action}", ['name' => $name])); } return Redirect::to("admin/{$this->name}")->with('error', trans('message.error')); } } return View::make("admin.{$this->name}.{$this->action}", ['name' => $this->name, 'action' => $this->action]); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Page(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Page'])) { // echo "<pre>";print_r($model->attributes); echo "</pre>"; $arr = $_POST["Page"]; if (empty($arr["user_id"])) { $arr['user_id'] = Yii::app()->user->id; } if (empty($arr["date"])) { $arr["date"] = time(); } if (empty($arr["status"])) { $setting = Settings::model()->findByPk(1); if ($setting->defaultPageStatus == 1) { $arr["status"] = 0; } else { $arr["status"] = 1; } } if (empty($arr["category_id"])) { $arr["category_id"] = 1; } $model->attributes = $arr; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function testPageUrlUnique() { // Create page with url that exists $page = new Page(); $page->setAttributes(array('category_id' => '1', 'publish_date' => '2011-12-01 18:55:06', 'status' => 'published', 'title' => 'Page Test Urls Unique', 'url' => 'page-1')); $this->assertTrue($page->save()); $this->assertEquals('page-1' . '-' . date('YmdHis'), $page->url); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return void * * @throws CDbException */ public function actionCreate() { $model = new Page(); $menuId = null; $menuParentId = 0; if (($data = Yii::app()->getRequest()->getPost('Page')) !== null) { $model->setAttributes($data); $transaction = Yii::app()->db->beginTransaction(); try { if ($model->save()) { // если активен модуль "Меню" - сохраним в меню if (Yii::app()->hasModule('menu')) { $menuId = (int) Yii::app()->getRequest()->getPost('menu_id'); $parentId = (int) Yii::app()->getRequest()->getPost('parent_id'); $menu = Menu::model()->findByPk($menuId); if ($menu) { if (!$menu->addItem($model->title, $model->getUrl(), $parentId, true)) { throw new CDbException(Yii::t('PageModule.page', 'There is an error when connecting page to menu...')); } } } Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('PageModule.page', 'Page was created')); $transaction->commit(); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create'])); } } catch (Exception $e) { $transaction->rollback(); $model->addError(false, $e->getMessage()); } } $languages = $this->yupe->getLanguagesList(); //если добавляем перевод $id = (int) Yii::app()->getRequest()->getQuery('id'); $lang = Yii::app()->getRequest()->getQuery('lang'); if (!empty($id) && !empty($lang)) { $page = Page::model()->findByPk($id); if (null === $page) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('PageModule.page', 'Targeting page was not found!')); $this->redirect(['index']); } if (!array_key_exists($lang, $languages)) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('PageModule.page', 'Language was not found!')); $this->redirect(['index']); } Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('PageModule.page', 'You add translation for {lang}', ['{lang}' => $languages[$lang]])); $model->lang = $lang; $model->slug = $page->slug; $model->category_id = $page->category_id; $model->title = $page->title; $model->title_short = $page->title_short; $model->parent_id = $page->parent_id; $model->order = $page->order; $model->layout = $page->layout; } else { $model->lang = Yii::app()->getLanguage(); } $this->render('create', ['model' => $model, 'pages' => Page::model()->getFormattedList(), 'languages' => $languages, 'menuId' => $menuId, 'menuParentId' => $menuParentId]); }
public function ___import($page, $data = null) { if (is_null($data)) { $data = $page; $page = new Page(); } if (empty($data['core_version'])) { throw new WireException("Invalid import data"); } $page->of(false); $page->resetTrackChanges(true); if (!is_array($data)) { throw new WireException("Data passed to import() must be an array"); } if (!$page->parent_id) { $parent = $this->wire('pages')->get($data['parent']); if (!$parent->id) { throw new WireException("Unknown parent: {$data['parent']}"); } $page->parent = $parent; } if (!$page->templates_id) { $template = $this->wire('templates')->get($data['template']); if (!$template) { throw new WireException("Unknown template: {$data['template']}"); } $page->template = $template; } $page->name = $data['name']; $page->sort = $data['sort']; $page->sortfield = $data['sortfield']; $page->status = $data['status']; $page->guid = $data['id']; if (!$page->id) { $page->save(); } foreach ($data['data'] as $name => $value) { $field = $this->wire('fields')->get($name); if (!$field) { $this->error("Unknown field: {$name}"); continue; } if ($data['types'][$name] != $field->type->className()) { $this->error("Import data for field '{$field->name}' has different fieldtype '" . $data['types'][$name] . "' != '" . $field->type->className() . "', skipping..."); continue; } $newStr = var_export($value, true); $oldStr = var_export($this->exportValue($page, $field, $page->get($field->name)), true); if ($newStr === $oldStr) { continue; } // value has not changed, so abort $value = $this->importValue($page, $field, $value); $page->set($field->name, $value); } return $page; }
public function add() { if (Page::already($_POST['baseUrl'], $_POST['uri'], $_POST['language'])) { throw new Exception('PAGE ALREADY EXISTS', 409); } $page = new Page(); $page->setBaseUrl($_POST['baseUrl']); $page->setUri($_POST['uri']); $page->setLanguage($_POST['language']); if (array_key_exists('content', $_POST) && !empty($_POST['content'])) { $page->setContent($_POST['content']); } $page->setModele($_POST['modele']); $page->setTitle($_POST['title']); if (array_key_exists('languageParentId', $_POST)) { $page->setLanguageParentId($_POST['languageParentId']); } if (array_key_exists('ajax', $_POST)) { $page->setAjax($_POST['ajax']); } if (array_key_exists('published', $_POST)) { $page->setPublished($_POST['published']); } if (array_key_exists('metas', $_POST)) { $page->setMetas($_POST['metas']); } if (array_key_exists('css', $_POST)) { $page->setCss($_POST['css']); } if (array_key_exists('js', $_POST)) { $page->setJs($_POST['js']); } if (array_key_exists('action', $_POST)) { $page->setAction($_POST['action']); } if (array_key_exists('method', $_POST)) { $page->setMethod($_POST['method']); } if (array_key_exists('priority', $_POST)) { $page->setPriority($_POST['priority']); } if (array_key_exists('datas', $_POST)) { $page->setDatas($_POST['datas']); } if (!array_key_exists('blockIds', $_POST)) { $blkIds = array(); foreach ($_POST['blockIds'] as $blk) { if (array_key_exists('id', $blk) && MongoId::isValid($blk['id'])) { $blkIds[] = $blk['id']; } } $this->page->setBlockIds($blkIds); } $page->save(); return array('pageId' => $page->getId()); }
public function getPage($slug) { $page = Page::where('slug', $slug)->first(); if (empty($page)) { $page = new Page(); $page->slug = $slug; $page->content = "Empty Page -> Please Edit in Admin Section"; $page->save(); } return View::make('site.pages.index', compact('page')); }
public function actionCreate() { $model = new Page(Page::SCENARIO_CREATE); $model->type = Page::TYPE_QA; $form = new Form('content.PageCForm', $model); if ($form->submitted() && $model->validate()) { $model->save(); $this->redirect(['index']); } $this->render('create', ['form' => $form]); }
public function save($title, $language, $content, $originalID = null, $originalLanguage = null, $preview = null) { $this->_adminTab = 'CreatePageAdminTab'; $page = new Page; $page->title = $title; $page->language = $language; $page->content = $content; $page->author = UserSession::get(); if ($originalID) { $page->originalID = $originalID; $page->originalLanguage = $originalLanguage; } try { if (!$preview) { $page->save(); if (!$originalID) { $this->notice(t('New page created')); $this->redirect('page', 'show', $page->ID); } else { $opage = Page::get($originalID, $originalLanguage); $this->notice(t('Saved translation of "%o"', array('o'=>$opage->title))); if ($language != CoOrg::getLanguage()) { $this->redirect('page', 'show', $page->ID, $language); } else { $this->redirect('page', 'show', $page->ID); } } } else { if ($originalID) $this->originalPage = Page::get($originalID, $originalLanguage); $this->newPage = $page; $this->render('admin/create'); } } catch (ValidationException $e) { if ($originalID) $this->originalPage = Page::get($originalID, $originalLanguage); $this->newPage = $page; $this->error(t('Creating page failed')); $this->render('admin/create'); } }
public function store() { $page = new Page(); $page->title = Input::get('title'); $page->slug = Str::slug(Input::get('title')); $page->body = Input::get('body'); $page->user_id = Sentry::getUser()->id; $page->save(); Notification::success('The page was saved.'); return Redirect::route('admin.pages.edit', $page->id); }
public function run() { $this->controller->layout = $this->layout; $model = new Page(ActiveRecord::SCENARIO_CREATE); $form = new Form('content.PageForm', $model); //$this->getController()->performAjaxValidation($model); if ($form->submitted() && $model->save()) { $this->controller->redirect(['view', 'id' => $model->id]); } $this->controller->render('create', ['form' => $form]); }
/** * Adds a new Page row with specified parent Id. * * @param int $parentId */ protected function addNewChildPage($parentId) { $db = Propel::getConnection(PagePeer::DATABASE_NAME); //$db->beginTransaction(); $parent = PagePeer::retrieveByPK($parentId); $page = new Page(); $page->setTitle('new page ' . time()); $page->insertAsLastChildOf($parent); $page->save(); //$db->commit(); }
public function actionCreate() { $model = new Page(); if (isset($_POST['Page'])) { $model->attributes = $_POST['Page']; $model->user_id = Yii::app()->user->id; if ($model->save()) { $this->redirect(array('userpage')); } } $this->render('create', array('model' => $model)); }
/** * Save any changes or additions that were made to these Notifications * * @return bool * */ public function save() { $of = $this->page->of(); if ($of) { $this->page->of(false); } $result = $this->page->save(SystemNotifications::fieldName, array('quiet' => true)); if ($of) { $this->page->of(true); } return $result; }
public function actionCreate() { $page = new Page(); if (isset($_POST['Page'])) { try { if ($page->save()) { if (Settings::get('SEO', 'slugs_enabled') && isset($_POST['Page']['slug'])) { $page->slug = Slug::create($_POST['Page']['slug'], array('view', 'id' => $page->id)); $page->save(); } $this->redirect(array('view', 'id' => $page->id)); } } catch (Exception $e) { $page->addError('', $e->getMessage()); } } elseif (isset($_GET['Page'])) { $page->attributes = $_GET['Page']; } // if (!isset($_POST['Page']['user'])) // $page->user = Yii::app()->user->id; $this->render('create', array('page' => $page)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Page(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Page'])) { $model->attributes = $_POST['Page']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function create_page($suburb) { $page = new Page($suburb, $this->suburb_template, $this->title_template, $this->page_template, $this->parent_page_id); $page->save(); $creation_method = $page->get_creation_method(); if ($creation_method == "Add") { $this->pages_added++; } else { if ($creation_method == "Update") { $this->pages_updated++; } } }
function postaddpage() { $thanhvien = new Page(); $nameimg = Input::file('images')->getClientOriginalName(); $thanhvien->title_page = Input::get('title'); $thanhvien->img_page = $nameimg; $thanhvien->des_page = Input::get('des'); $thanhvien->content_page = Input::get('content'); $thanhvien->save(); Input::file('images')->move('img', $nameimg); $aa = Input::file('images')->getRealPath(); return Redirect::to('login'); }
* @param integer $id the ID of the model to be displayed */ public function actionView($id) { $this->render('view', array('model' => $this->loadModel($id))); } /** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Page(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model);
function save($id = FALSE) { $this->db->debug = true; if ($_POST) { $page = new Page($id); $_POST['title'] = lang_encode($_POST['title']); $_POST['detail'] = lang_encode($_POST['detail']); $_POST['user_id'] = $this->session->userdata('id'); $page->from_array($_POST); $page->save(); set_notify('success', lang('save_data_complete')); } //redirect('pages/admin/pages'); }
function goto_tasks_page_for_user() { $user = Users::findById($this->request->getId('selected_user_id')); $page_title = $user->getName() . ' - Task List'; $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME, $link); $query = "select id from healingcrystals_project_objects where type='Page' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='" . mysql_real_escape_string($page_title) . "'"; $result = mysql_query($query, $link); if (mysql_num_rows($result)) { $info = mysql_fetch_assoc($result); $this->redirectToUrl(assemble_url('project_page', array('project_id' => TASK_LIST_PROJECT_ID, 'page_id' => $info['id']))); } else { $query = "select id from healingcrystals_project_objects where type='Category' and module='pages' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='General'"; $page_category = mysql_query($query); $page_category_info = mysql_fetch_assoc($page_category); $page_data = array('type' => 'Page', 'module' => 'pages', 'visibility' => VISIBILITY_NORMAL, 'name' => $page_title, 'body' => 'Auto-generated Task List Page', 'integer_field_1' => '1'); db_begin_work(); $this->active_page = new Page(); $this->active_page->setAttributes($page_data); $this->active_page->setProjectId(TASK_LIST_PROJECT_ID); $this->active_page->setCreatedBy($this->logged_user); $this->active_page->setState(STATE_VISIBLE); $this->active_page->setParentId($page_category_info['id']); $save = $this->active_page->save(); if ($save && !is_error($save)) { //$subscribers = array($this->logged_user->getId()); //if(!in_array($this->active_project->getLeaderId(), $subscribers)) { // $subscribers[] = $this->active_project->getLeaderId(); //} //Subscriptions::subscribeUsers($subscribers, $this->active_page); db_commit(); $this->active_page->ready(); $query = "select * from healingcrystals_project_users where user_id='" . $user->getId() . "' and project_id='" . TASK_LIST_PROJECT_ID . "'"; $result = mysql_query($query, $link); if (!mysql_num_rows($result)) { //mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $user->getId() . "', '" . TASK_LIST_PROJECT_ID . "', '" . $user->getRoleId() . "', 'N;')"); mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $user->getId() . "', '" . TASK_LIST_PROJECT_ID . "', '7', 'N;')"); } elseif ($user->getRoleId() == '2') { mysql_query("update healingcrystals_project_users set role_id='7' where user_id='" . $user->getId() . "' and project_id='" . TASK_LIST_PROJECT_ID . "'"); } $this->redirectToUrl(assemble_url('project_page', array('project_id' => TASK_LIST_PROJECT_ID, 'page_id' => $this->active_page->getId()))); } else { db_rollback(); //$save .= 'rollback'; } } mysql_close($link); $this->smarty->assign(array('user' => $user, 'project' => $this->active_project, 'errors' => $save, 'data' => $page_data)); }
public function actionCreate() { $model = new Page(); if (isset($_POST['Page'])) { $model->setAttributes($_POST['Page']); if ($model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('admin')); } } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * * @param integer $parentId */ public function actionCreate($parentId) { $model = new Page(); $model->parent_id = $parentId + 0; $model->layout = 'main'; $model->view = 'view'; $this->breadcrumbs = Page::getBreadcrumbs($parentId, 'Добавление'); if (isset($_POST['Page'])) { $model->attributes = $_POST['Page']; if ($model->save()) { $this->redirect(array('index', 'parentId' => $model->parent_id)); } } $this->render('form', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Page(); if (isset($_POST['Page'])) { $model->attributes = $_POST['Page']; if ($model->save()) { Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('page', 'Страница добавлена!')); if (isset($_POST['saveAndClose'])) { $this->redirect(array('admin')); } $this->redirect(array('update', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'pages' => Page::model()->getAllPagesList())); }
public function run() { $model = new Page(); if (isset($_POST['Page'])) { $model->attributes = $_POST['Page']; //摘要 $model->introduce = trim($_POST['Page']['introduce']) ? $_POST['Page']['introduce'] : Helper::truncate_utf8_string(preg_replace('/\\s+/', ' ', $_POST['Page']['content']), 200); $model->create_time = time(); $model->update_time = $model->create_time; if ($model->save()) { $this->controller->message('success', Yii::t('admin', 'Add Success'), $this->controller->createUrl('index')); } } $this->controller->render('create', array('model' => $model)); }