Advertisement
Guest User

Untitled

a guest
May 22nd, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.73 KB | None | 0 0
  1. //add.ctp
  2. <?php $javascript->link('ckeditor/ckeditor', false);?>
  3.  
  4. <?php echo $form->create(); ?>
  5. <?php echo $form->input('id'); ?>
  6. <?php echo $form->input('name'); ?>
  7.  
  8. <?php //echo $form->label('Html'); ?>
  9. <?php //echo $form->textarea('html', array('rows'=>20, 'cols'=>50)); ?>
  10.  
  11. <b>Tags:</b>
  12. <br>
  13. <b>$WEBROOT</b> Diretório onde ficam os arquivos (ex: <u>$WEBROOT/swf/inicial.swf</u> ou <u>$WEBROOT/img/user.png</u>)
  14. <br><br>
  15.  
  16. <?php echo $form->textarea('html', array('class'=>'ckeditor')); ?>
  17. <?php echo $form->end('Salvar'); ?>-bash-3.2$
  18. -bash-3.2$ cat add.ctp
  19. <?php $javascript->link('ckeditor/ckeditor', false);?>
  20.  
  21. <?php echo $form->create(); ?>
  22. <?php echo $form->input('id'); ?>
  23. <?php echo $form->input('name'); ?>
  24.  
  25. <?php //echo $form->label('Html'); ?>
  26. <?php //echo $form->textarea('html', array('rows'=>20, 'cols'=>50)); ?>
  27.  
  28. <b>Tags:</b>
  29. <br>
  30. <b>$WEBROOT</b> Diretório onde ficam os arquivos (ex: <u>$WEBROOT/swf/inicial.swf</u> ou <u>$WEBROOT/img/user.png</u>)
  31. <br><br>
  32.  
  33. <?php echo $form->textarea('html', array('class'=>'ckeditor')); ?>
  34. <?php echo $form->end('Salvar'); ?>
  35.  
  36. //edit.ctp (here is where it happens)
  37. -bash-3.2$ cat edit.ctp
  38. <?php echo $this->render('add', false); ?>
  39.  
  40. //the controller
  41. -bash-3.2$ cat menu_admin_controller.php
  42. <?php
  43. class MenuAdminController extends AppController
  44. {
  45.     var $pageTitle = 'Gerenciamento de menus do site';
  46.     var $uses = array('Menu');
  47.     var $helpers = array('datagrid');
  48.     var $components = array('Auth');
  49.  
  50.     function index()
  51.     {
  52.         $filters['Menu.is_static'] = FALSE;
  53.         $this->set('data', $this->paginate('Menu', $filters));
  54.     }
  55. }
  56. ?>
  57.  
  58. //here is the app_controller
  59. -bash-3.2$ cat app_controller.php
  60. <?php
  61. class AppController extends Controller
  62. {
  63.     function __construct()
  64.     {
  65.         parent::__construct();
  66.         $this->helpers[]    = 'html';
  67.         $this->helpers[]    = 'javascript';
  68.         $this->helpers[]    = 'js';
  69.         $this->helpers[]    = 'ajax';
  70.         $this->helpers[]    = 'session';
  71.         $this->components[] = 'RequestHandler';
  72.         $this->uses[]       = 'MenuProduct';
  73.         $this->uses[]       = 'Menu';
  74.         $this->uses[] = 'Background';
  75.         $this->uses[] = 'MenuImages';
  76.         $this->uses[] = 'Category';
  77.         $this->uses[] = 'Promotion';
  78.         $this->uses[] = 'PromotionImage';
  79.     }
  80.  
  81.     function beforeFilter()
  82.     {
  83.         Security::setHash("md5");
  84.         $this->set('product_categories', $this->MenuProduct->findAll(null, null, array('MenuProduct.position')));
  85.         $this->set('menu_categorias', $this->Category->find('all', array('order' => 'Category.position')));        
  86.         $this->set('menu_images', $this->MenuImages->find('all', array('recursive' => -1)));
  87.         $this->set('menu_list', $this->Menu->findAll());
  88.         $this->set('background', $this->Background->find('first', array('conditions' => array('isbackground' => true))));
  89.         $this->set('promotion_images', $this->PromotionImage->findAll());
  90.     }
  91.  
  92.     function afterFilter()
  93.     {
  94.     }
  95.  
  96.     function _getLocation()
  97.     {
  98.         $url = $this->params['named'];
  99.         $url['controller'] = $this->params['controller'];
  100.         $url['action'] = 'index';
  101.         return $url;
  102.     }
  103.  
  104.     function add()
  105.     {
  106.         if (!empty($this->data))
  107.         {
  108.             $this->_save();
  109.         }
  110.     }
  111.  
  112.     function edit($id)
  113.     {
  114.         if (empty($this->data))
  115.         {
  116.             $class = $this->modelClass;
  117.             $this->data = $this->$class->find('first', array('conditions' => array("{$class}.id" => $id)));
  118.         }
  119.         else
  120.         {
  121.             $this->_save();
  122.         }
  123.     }
  124.  
  125.  
  126.     function _save()
  127.     {
  128.     //echo "<!--";
  129.        // var_dump($_POST);
  130.     //var_dump($_REQUEST);
  131.         //echo "-->";
  132.     //exit(0);
  133.  
  134.         $class = $this->modelClass;
  135.         if ($this->$class->saveAll($this->data))
  136.         {
  137.             $this->Session->setFlash('Registro salvo com sucesso');        
  138.             $this->redirect( $this->_getLocation() );
  139.         }
  140.     }
  141.  
  142.  
  143.     function delete($id)
  144.     {
  145.         $ok = false;
  146.         $class = $this->modelClass;
  147.         if ($this->$class->delete($id))
  148.         {
  149.             $this->Session->setFlash('Registro removido com sucesso.');
  150.             $this->redirect( $this->_getLocation() );
  151.             $ok = true;
  152.         }
  153.         return $ok;
  154.     }
  155.  
  156.  
  157.     /**
  158.      *
  159.      * Reorganiza uma lista via drag-n-drop ajax
  160.      *
  161.      * @return <type>
  162.      */
  163.     function reorganize()
  164.     {
  165.         $reorganize = $this->params['form']['reorganize'];
  166.         if (!isset($reorganize) || !is_array($reorganize))
  167.         {
  168.             return;
  169.         }
  170.         foreach ($reorganize as $key => $positions)
  171.         {
  172.             if (!is_array($positions))
  173.             {
  174.                 return;
  175.             }
  176.             foreach ($positions as $position => $id)
  177.             {
  178.                 $this->{$this->modelClass}->read('position', $id);
  179.                 $this->{$this->modelClass}->set(array(
  180.                     'position' => $position
  181.                 ));
  182.                 $this->{$this->modelClass}->save();
  183.             }
  184.         }
  185.     }
  186.  
  187.     /**
  188.      *
  189.      * Identico ao reorganize() mas com lista simples
  190.      *
  191.      * @return <type>
  192.      */
  193.     function reorganizesimple()
  194.     {
  195.         $listId = $this->params['form']['reorganize'];
  196.        
  197.         if (!isset($listId) || !is_array($listId))
  198.         {
  199.             return;
  200.         }
  201.         foreach ($listId as $position => $id)
  202.         {
  203.             $this->{$this->modelClass}->read('position', $id);
  204.             $this->{$this->modelClass}->set(array(
  205.                 'position' => $position
  206.             ));
  207.             $this->{$this->modelClass}->save();
  208.         }
  209.     }
  210. }
  211. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement