04.01
php
saved
Vangel
Note
Artiicles controller
Artiicles controller
- <?php
- class ArticlesController extends AppController {
- var $name = 'Articles';
- // var $view = 'Article';
- function index() {
- $this->Article->recursive = 0;
- $this->set('articles', $this->paginate());
- }
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid Article.', true));
- }
- $this->set('article', $this->Article->read(null, $id));
- //$this->Session->read('lang');
- }
- function add() {
- $this->Article->create();
- if ($this->Article->save($this->data)) {
- $this->Session->setFlash(__('The Article has been saved', true));
- //$this->redirect(array('action'=>'index'));
- } else {
- $this->Session->setFlash(__('The Article could not be saved. Please, try again.', true));
- }
- }
- $sections = $this->Article->Section->find('list');
- }
- function edit($id = null) {
- $this->Session->setFlash(__('Invalid Article', true));
- }
- if ($this->Article->save($this->data)) {
- $this->Session->setFlash(__('The Article has been saved', true));
- } else {
- $this->Session->setFlash(__('The Article could not be saved. Please, try again.', true));
- }
- }
- $this->data = $this->Article->read(null, $id);
- }
- $sections = $this->Article->Section->find('list');
- }
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for Article', true));
- }
- if ($this->Article->del($id)) {
- $this->Session->setFlash(__('Article deleted', true));
- }
- }
- function admin_index() {
- $this->Article->recursive = 0;
- $this->set('articles', $this->paginate());
- }
- function admin_view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid Article.', true));
- }
- $this->set('article', $this->Article->read(null, $id));
- }
- function admin_add() {
- $this->Article->create();
- if ($this->Article->save($this->data)) {
- $this->Session->setFlash(__('The Article has been saved', true));
- } else {
- $this->Session->setFlash(__('The Article could not be saved. Please, try again.', true));
- }
- }
- $sections = $this->Article->Section->find('list');
- }
- function admin_edit($id = null) {
- $this->Session->setFlash(__('Invalid Article', true));
- }
- if ($this->Article->save($this->data)) {
- $this->Session->setFlash(__('The Article has been saved', true));
- } else {
- $this->Session->setFlash(__('The Article could not be saved. Please, try again.', true));
- }
- }
- $this->data = $this->Article->read(null, $id);
- }
- $sections = $this->Article->Section->find('list');
- }
- function admin_delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for Article', true));
- }
- if ($this->Article->del($id)) {
- $this->Session->setFlash(__('Article deleted', true));
- }
- }
- function lang($lng = 'en'){
- $data = $this->Article->findAllByLanguage($lng);
- $this->set('data',$data);
- }
- function body($id = null){
- if (!$id) {
- $this->Session->setFlash(__('Invalid Article.', true));
- }
- $this->set('article', $this->Article->read('body_en', $id));
- }
- function getAllArticles(){
- // Bad bad function, ignoring you
- // Configure::write('debug', '0'); //set debug to 0 for this function because debugging info breaks the XMLHttpRequest
- // $this->layout = "ajax"; //this tells the controller to use the Ajax layout instead of the default layout (since we're using ajax . . .)
- $count = $this->Article->findCount(); //counts the number of records in User.
- $articleA = $this->Article->findAll(null,'*','published DESC'); //gets all the User records and sorts them by username alphabetically.
- $articleArray = Set::extract($articleA, '{n}.title_en'); //convert $userArray into a json-friendly format
- $this->set('total', $count); //send total to the view
- $this->set('articles',$articleArray); //s
- }
- function beforeRender(){
- // Configure::write('Config.language', 'en');
- $this->Session->write('lang','en');
- $this->Articles->Session = $this->Session;
- }
- }
- ?>
Parsed in 0.312 seconds, using GeSHi 1.0.7.14