Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [app/views/users/add.ctp]
- <div class="users form">
- <?php echo $this->Form->create('User');?>
- <fieldset>
- <legend><?php __('Add User'); ?></legend>
- <?php
- echo $this->Form->input('username');
- echo $this->Form->input('password');
- echo $this->Form->input('group_id');
- ?>
- </fieldset>
- <?php echo $this->Form->end(__('Submit', true));?>
- </div>
- <div class="actions">
- <h3><?php __('Actions'); ?></h3>
- <ul>
- <li><?php echo $this->Html->link(__('List Users', true), array('action' => 'index'));?></li>
- <li><?php echo $this->Html->link(__('List Groups', true), array('controller' => 'groups', 'action' => 'index')); ?> </li>
- <li><?php echo $this->Html->link(__('New Group', true), array('controller' => 'groups', 'action' => 'add')); ?> </li>
- <li><?php echo $this->Html->link(__('List Posts', true), array('controller' => 'posts', 'action' => 'index')); ?> </li>
- <li><?php echo $this->Html->link(__('New Post', true), array('controller' => 'posts', 'action' => 'add')); ?> </li>
- </ul>
- </div>
- [app/controller/users_controller.php]
- <?php
- class UsersController extends AppController {
- var $name = 'Users';
- function index() {
- $this->User->recursive = 0;
- $this->set('users', $this->paginate());
- }
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid user', true));
- $this->redirect(array('action' => 'index'));
- }
- $this->set('user', $this->User->read(null, $id));
- }
- function add() {
- if (!empty($this->data)) {
- $this->User->create();
- if ($this->User->save($this->data)) {
- $this->Session->setFlash(__('The user has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
- }
- }
- $groups = $this->User->Group->find('list');
- $this->set(compact('groups'));
- }
- function edit($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid user', true));
- $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->data)) {
- if ($this->User->save($this->data)) {
- $this->Session->setFlash(__('The user has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->User->read(null, $id);
- }
- $groups = $this->User->Group->find('list');
- $this->set(compact('groups'));
- }
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for user', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->User->delete($id)) {
- $this->Session->setFlash(__('User deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->Session->setFlash(__('User was not deleted', true));
- $this->redirect(array('action' => 'index'));
- }
- function login()
- {
- if ($this->Session->read('Auth.User'))
- {
- $this->Session->setFlash('You are logged in!');
- $this->redirect('/', null, false);
- }
- }
- function logout()
- {
- $this->Session->setFlash('Good-Bye');
- $this->redirect($this->Auth->logout());
- }
- function beforeFilter()
- {
- parent::beforeFilter();
- $this->Auth->allow(array('*'));
- }
- }
- [app/models/user.php]
- <?php
- class User extends AppModel {
- var $name = 'User';
- var $validate = array(
- 'username' => array(
- 'notempty' => array(
- 'rule' => array('notempty'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'password' => array(
- 'notempty' => array(
- 'rule' => array('notempty'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'group_id' => array(
- 'numeric' => array(
- 'rule' => array('numeric'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- );
- //The Associations below have been created with all possible keys, those that are not needed can be removed
- var $belongsTo = array(
- 'Group' => array(
- 'className' => 'Group',
- 'foreignKey' => 'group_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- )
- );
- var $hasMany = array(
- 'Post' => array(
- 'className' => 'Post',
- 'foreignKey' => 'user_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- )
- );
- var $actsAs = array('Acl' => array('type' => 'requester'));
- function parentNode()
- {
- if (!$this->id && empty($this->data))
- {
- return null;
- }
- if (isset($this->data['User']['group_id']))
- {
- $groupId = $this->data['User']['group_id'];
- }
- else
- {
- $groupId = $this->field('group_id');
- }
- if (!$groupId)
- {
- return null;
- }
- else
- {
- return array('Group' => array('id' => $groupId));
- }
- }
- function bindNode($user)
- {
- return array('model' => 'Group', 'foreign_key' => $user['User']['group_id']);
- }
- }
- [app/models/group.php]
- <?php
- class Group extends AppModel {
- var $name = 'Group';
- var $actsAs = array('Acl' => array('type' => 'requester'));
- var $validate = array(
- 'name' => array(
- 'notempty' => array(
- 'rule' => array('notempty'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- );
- //The Associations below have been created with all possible keys, those that are not needed can be removed
- var $hasMany = array(
- 'User' => array(
- 'className' => 'User',
- 'foreignKey' => 'group_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- )
- );
- function parentNode()
- {
- return null;
- }
- }
- [sql schema]
- -- phpMyAdmin SQL Dump
- -- version 3.2.4
- -- http://www.phpmyadmin.net
- --
- -- Host: localhost
- -- Generation Time: Jul 21, 2011 at 11:36 AM
- -- Server version: 5.1.41
- -- PHP Version: 5.3.1
- SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
- --
- -- Database: `cake_v1`
- --
- -- --------------------------------------------------------
- --
- -- Table structure for table `acos`
- --
- CREATE TABLE IF NOT EXISTS `acos` (
- `id` int(10) NOT NULL AUTO_INCREMENT,
- `parent_id` int(10) DEFAULT NULL,
- `model` varchar(255) DEFAULT NULL,
- `foreign_key` int(10) DEFAULT NULL,
- `alias` varchar(255) DEFAULT NULL,
- `lft` int(10) DEFAULT NULL,
- `rght` int(10) DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
- --
- -- Dumping data for table `acos`
- --
- INSERT INTO `acos` (`id`, `parent_id`, `model`, `foreign_key`, `alias`, `lft`, `rght`) VALUES
- (1, NULL, NULL, NULL, 'controllers', 1, 2);
- -- --------------------------------------------------------
- --
- -- Table structure for table `aros`
- --
- CREATE TABLE IF NOT EXISTS `aros` (
- `id` int(10) NOT NULL AUTO_INCREMENT,
- `parent_id` int(10) DEFAULT NULL,
- `model` varchar(255) DEFAULT NULL,
- `foreign_key` int(10) DEFAULT NULL,
- `alias` varchar(255) DEFAULT NULL,
- `lft` int(10) DEFAULT NULL,
- `rght` int(10) DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
- --
- -- Dumping data for table `aros`
- --
- INSERT INTO `aros` (`id`, `parent_id`, `model`, `foreign_key`, `alias`, `lft`, `rght`) VALUES
- (1, NULL, 'Group', 2, NULL, 1, 10),
- (2, NULL, 'Group', 3, NULL, 11, 14),
- (3, NULL, 'Group', 4, NULL, 15, 18),
- (4, 1, 'User', 1, NULL, 2, 3),
- (5, 2, 'User', 2, NULL, 12, 13),
- (6, 1, 'User', 3, NULL, 4, 5),
- (7, 1, 'User', 4, NULL, 6, 7),
- (8, 1, 'User', 5, NULL, 8, 9),
- (9, 3, 'User', 6, NULL, 16, 17);
- -- --------------------------------------------------------
- --
- -- Table structure for table `aros_acos`
- --
- CREATE TABLE IF NOT EXISTS `aros_acos` (
- `id` int(10) NOT NULL AUTO_INCREMENT,
- `aro_id` int(10) NOT NULL,
- `aco_id` int(10) NOT NULL,
- `_create` varchar(2) NOT NULL DEFAULT '0',
- `_read` varchar(2) NOT NULL DEFAULT '0',
- `_update` varchar(2) NOT NULL DEFAULT '0',
- `_delete` varchar(2) NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- UNIQUE KEY `ARO_ACO_KEY` (`aro_id`,`aco_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
- --
- -- Dumping data for table `aros_acos`
- --
- INSERT INTO `aros_acos` (`id`, `aro_id`, `aco_id`, `_create`, `_read`, `_update`, `_delete`) VALUES
- (1, 1, 1, '-1', '-1', '-1', '-1'),
- (2, 2, 1, '-1', '-1', '-1', '-1');
- -- --------------------------------------------------------
- --
- -- Table structure for table `groups`
- --
- CREATE TABLE IF NOT EXISTS `groups` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(100) NOT NULL,
- `created` datetime DEFAULT NULL,
- `modified` datetime DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
- --
- -- Dumping data for table `groups`
- --
- INSERT INTO `groups` (`id`, `name`, `created`, `modified`) VALUES
- (2, 'administrators', '2011-06-15 19:44:50', '2011-06-15 19:45:06'),
- (3, 'managers', '2011-06-15 19:45:16', '2011-06-15 19:45:16'),
- (4, 'users', '2011-06-15 19:45:25', '2011-06-15 19:45:25');
- -- --------------------------------------------------------
- --
- -- Table structure for table `posts`
- --
- CREATE TABLE IF NOT EXISTS `posts` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `user_id` int(11) NOT NULL,
- `title` varchar(255) NOT NULL,
- `body` text,
- `created` datetime DEFAULT NULL,
- `modified` datetime DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
- --
- -- Dumping data for table `posts`
- --
- -- --------------------------------------------------------
- --
- -- Table structure for table `users`
- --
- CREATE TABLE IF NOT EXISTS `users` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `username` varchar(255) NOT NULL,
- `password` char(40) NOT NULL,
- `group_id` int(11) NOT NULL,
- `created` datetime DEFAULT NULL,
- `modified` datetime DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `username` (`username`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
- --
- -- Dumping data for table `users`
- --
- INSERT INTO `users` (`id`, `username`, `password`, `group_id`, `created`, `modified`) VALUES
- (1, 'sathya', 'a0dafbf8db589b2f90c09798b24e3b2732325ebc', 2, '2011-06-17 18:17:12', '2011-06-17 18:17:12'),
- (2, 'sathya_two', 'a0dafbf8db589b2f90c09798b24e3b2732325ebc', 3, '2011-06-17 18:18:01', '2011-06-17 18:18:01'),
- (3, 'raju', 'a0dafbf8db589b2f90c09798b24e3b2732325ebc', 2, '2011-06-18 12:20:46', '2011-06-18 12:20:46'),
- (4, 'raju_2', '8b73d35d607c405f8f74f715a031beeb57f5e4a4', 2, '2011-06-18 12:21:27', '2011-06-18 12:21:27'),
- (5, 'sathyashrayan', '579383613f4ac6328a621080fc61a69b32ee618b', 2, '2011-06-23 12:35:22', '2011-06-23 12:35:22'),
- (6, 'sathyashrayan.n@ameexusa.com', 'e1e9d096378712b99d1ef7abe33405260fabda63', 4, '2011-07-21 11:22:58', '2011-07-21 11:23:55');
- -- --------------------------------------------------------
- --
- -- Table structure for table `widgets`
- --
- CREATE TABLE IF NOT EXISTS `widgets` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(100) NOT NULL,
- `part_no` varchar(12) DEFAULT NULL,
- `quantity` int(11) DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
- --
- -- Dumping data for table `widgets`
- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement