Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //add.ctp
- <?php $javascript->link('ckeditor/ckeditor', false);?>
- <?php echo $form->create(); ?>
- <?php echo $form->input('id'); ?>
- <?php echo $form->input('name'); ?>
- <?php //echo $form->label('Html'); ?>
- <?php //echo $form->textarea('html', array('rows'=>20, 'cols'=>50)); ?>
- <b>Tags:</b>
- <br>
- <b>$WEBROOT</b> Diretório onde ficam os arquivos (ex: <u>$WEBROOT/swf/inicial.swf</u> ou <u>$WEBROOT/img/user.png</u>)
- <br><br>
- <?php echo $form->textarea('html', array('class'=>'ckeditor')); ?>
- <?php echo $form->end('Salvar'); ?>-bash-3.2$
- -bash-3.2$ cat add.ctp
- <?php $javascript->link('ckeditor/ckeditor', false);?>
- <?php echo $form->create(); ?>
- <?php echo $form->input('id'); ?>
- <?php echo $form->input('name'); ?>
- <?php //echo $form->label('Html'); ?>
- <?php //echo $form->textarea('html', array('rows'=>20, 'cols'=>50)); ?>
- <b>Tags:</b>
- <br>
- <b>$WEBROOT</b> Diretório onde ficam os arquivos (ex: <u>$WEBROOT/swf/inicial.swf</u> ou <u>$WEBROOT/img/user.png</u>)
- <br><br>
- <?php echo $form->textarea('html', array('class'=>'ckeditor')); ?>
- <?php echo $form->end('Salvar'); ?>
- //edit.ctp (here is where it happens)
- -bash-3.2$ cat edit.ctp
- <?php echo $this->render('add', false); ?>
- //the controller
- -bash-3.2$ cat menu_admin_controller.php
- <?php
- class MenuAdminController extends AppController
- {
- var $pageTitle = 'Gerenciamento de menus do site';
- var $uses = array('Menu');
- var $helpers = array('datagrid');
- var $components = array('Auth');
- function index()
- {
- $filters['Menu.is_static'] = FALSE;
- $this->set('data', $this->paginate('Menu', $filters));
- }
- }
- ?>
- //here is the app_controller
- -bash-3.2$ cat app_controller.php
- <?php
- class AppController extends Controller
- {
- function __construct()
- {
- parent::__construct();
- $this->helpers[] = 'html';
- $this->helpers[] = 'javascript';
- $this->helpers[] = 'js';
- $this->helpers[] = 'ajax';
- $this->helpers[] = 'session';
- $this->components[] = 'RequestHandler';
- $this->uses[] = 'MenuProduct';
- $this->uses[] = 'Menu';
- $this->uses[] = 'Background';
- $this->uses[] = 'MenuImages';
- $this->uses[] = 'Category';
- $this->uses[] = 'Promotion';
- $this->uses[] = 'PromotionImage';
- }
- function beforeFilter()
- {
- Security::setHash("md5");
- $this->set('product_categories', $this->MenuProduct->findAll(null, null, array('MenuProduct.position')));
- $this->set('menu_categorias', $this->Category->find('all', array('order' => 'Category.position')));
- $this->set('menu_images', $this->MenuImages->find('all', array('recursive' => -1)));
- $this->set('menu_list', $this->Menu->findAll());
- $this->set('background', $this->Background->find('first', array('conditions' => array('isbackground' => true))));
- $this->set('promotion_images', $this->PromotionImage->findAll());
- }
- function afterFilter()
- {
- }
- function _getLocation()
- {
- $url = $this->params['named'];
- $url['controller'] = $this->params['controller'];
- $url['action'] = 'index';
- return $url;
- }
- function add()
- {
- if (!empty($this->data))
- {
- $this->_save();
- }
- }
- function edit($id)
- {
- if (empty($this->data))
- {
- $class = $this->modelClass;
- $this->data = $this->$class->find('first', array('conditions' => array("{$class}.id" => $id)));
- }
- else
- {
- $this->_save();
- }
- }
- function _save()
- {
- //echo "<!--";
- // var_dump($_POST);
- //var_dump($_REQUEST);
- //echo "-->";
- //exit(0);
- $class = $this->modelClass;
- if ($this->$class->saveAll($this->data))
- {
- $this->Session->setFlash('Registro salvo com sucesso');
- $this->redirect( $this->_getLocation() );
- }
- }
- function delete($id)
- {
- $ok = false;
- $class = $this->modelClass;
- if ($this->$class->delete($id))
- {
- $this->Session->setFlash('Registro removido com sucesso.');
- $this->redirect( $this->_getLocation() );
- $ok = true;
- }
- return $ok;
- }
- /**
- *
- * Reorganiza uma lista via drag-n-drop ajax
- *
- * @return <type>
- */
- function reorganize()
- {
- $reorganize = $this->params['form']['reorganize'];
- if (!isset($reorganize) || !is_array($reorganize))
- {
- return;
- }
- foreach ($reorganize as $key => $positions)
- {
- if (!is_array($positions))
- {
- return;
- }
- foreach ($positions as $position => $id)
- {
- $this->{$this->modelClass}->read('position', $id);
- $this->{$this->modelClass}->set(array(
- 'position' => $position
- ));
- $this->{$this->modelClass}->save();
- }
- }
- }
- /**
- *
- * Identico ao reorganize() mas com lista simples
- *
- * @return <type>
- */
- function reorganizesimple()
- {
- $listId = $this->params['form']['reorganize'];
- if (!isset($listId) || !is_array($listId))
- {
- return;
- }
- foreach ($listId as $position => $id)
- {
- $this->{$this->modelClass}->read('position', $id);
- $this->{$this->modelClass}->set(array(
- 'position' => $position
- ));
- $this->{$this->modelClass}->save();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement