I am facing some problem of calling to a member function create() on a non-object
please help me out,My code is :-
<?php
echo $form->create('Register', array('action' => 'register'));
echo $form->input('username');
echo $form->input('password');
echo $form->input('cnfrmpassword', array('type' => 'password'));
echo $form->submit();
echo $form->end();
?>
Try like this.... You're missing $this-> before the helper.
<?php
echo $this->Form->create('User', array('action' => 'register'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('cnfrmpassword', array('type' => 'password'));
echo $this->Form->end('Submit');
?>
Related
How to fix this issue
Error: userHelper could not be found.
this is my search.ctp inside element which is called in default.ctp
<?php echo $this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'search']], array('type' => 'get')); ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->button('Search', ['type' => 'submit']); ?>
Below is my search controller
public function search() {
$value = $this->request->getData('username');
$results = $this->Users->find('all', ['fields'=>[
'Users.username',
'Users.email',
'Users.id',
'Users.age',
'Users.address',
'Users.gender'
],
'order' => 'Users.id ASC',
'conditions' => array(' username LIKE' => "%".$value."%")
]);
$this->set('user', $results);
$this->set('_serialize', ['user']);
}
search.ctp inside users
<?php
use Cake\ORM\TableRegistry;
use Cake\Filesystem\Folder;
use App\Controller\AppController;
?>
<?php foreach ($user as $users): ?>
<?php echo $this->users->username;?>
<?php endforeach;?>
What is the line inside loop? It shouldn't be.
$this->users->username;
I'm not so sure returning as a array or object in cakephp 3.
But, I'm sure that it should be like that,
$users->username;
or
$users['username'];
I have events that have a datetime input for the start and end of the event. If I try to save the start 12-8-2015 at 11:30am and the end 12-8-2015 at 12:30pm the event gets save but it makes the date 12-9-2015. I don't know why it is doing this. I have tried adding validation rules like 'datetime', and 'notBlank', but that would just give me errors saying the fields were invalid and/or required. So I took the validation rules out. Any suggestions why the behavior is so weird with datetime?
Form:
<?= $this->Form->create($event, ['type' => 'file']);?>
<fieldset>
<legend><?= __('Edit Event'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('event_type_id');
echo $this->Form->input('event_img', ['type' => 'file']);
echo $this->Form->input('title');
echo $this->Form->input('location');
echo $this->Form->input('details');
echo $this->Form->input('cost');
echo $this->Form->label('Start Time');
echo $this->Form->datetime('start', ['interval' => 15, 'timeFormat' => 12]);
echo $this->Form->label('End Time');
echo $this->Form->datetime('end', ['interval' => 15, 'timeFormat' => 12]);
echo $this->Form->input('all_day');
echo $this->Form->input('status', ['options' => [
'Scheduled' => 'Scheduled','Confirmed' => 'Confirmed','In Progress' => 'In Progress',
'Rescheduled' => 'Rescheduled','Completed' => 'Completed'
]
]
);
?>
</fieldset>
<?= $this->Form->button(__('Submit', true));?>
<?= $this->Form->end(); ?>
I have created a CommentManager plugin for adding comments in my posts. Adding the comment form in Posts/view.ctp file and the comment form action is redirecting to CommentManager/Comments/add.
The comments are saving properly but when saving empty form, that doesn't shows the validation error messages which i have written in CommentsTable and also the entered data has gone from the form.
CommentManager/src/Controller/CommentsController/add
public function add()
{
$ccomment = $this->Comments->newEntity($this->request->data);
if ($this->request->is('post')) {
$newData = ['post_id' => $this->request->params['pass'][0]];
$ccomment = $this->Comments->patchEntity($ccomment, $newData);
if ($this->Comments->save($ccomment)) {
$this->Flash->success('The comment has been saved.');
return $this->redirect($_SERVER['HTTP_REFERER']);
} else {
$this->Flash->error('The comment could not be saved. Please, try again.');
}
}
$this->set(compact('ccomment'));
return $this->redirect($_SERVER['HTTP_REFERER']);
}
CommentManager/src/Model/Table/CommentsTable
public function validationDefault(Validator $validator) {
return $validator
->notEmpty('body', 'Body contents required.')
->notEmpty('email', 'An email is required.')
->add('email', [
'format' => [
'rule' => [
'custom',
'/^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
],
'message' => 'Enter a valid email.'
]
]);
}
src/Template/Posts/view.ctp
<?php echo $this->Html->link('Back', ['action' => 'index']) ?>
<?php echo $this->element('check_login'); ?>
<br/>
<?php $img_path = DS.'webroot'.DS.'images'.DS.$post->image; ?>
<img src="<?php echo empty($post->image)?'':$img_path; ?>">
<h2><?php echo $post->title; ?></h2>
<p><?php echo $post->body; ?></p>
<p><small><?php echo $post->created->format('d M Y'); ?></small></p>
<h3>Comments:</h3>
<?php foreach ($comments as $comment) { ?>
<p><?php echo $comment->body; ?></p>
<?php } ?>
<?php
echo $this->Form->create(null, ['url' => ['plugin' => 'CommentManager', 'controller' => 'Comments', 'action' => 'add', $post->id]]);
echo $this->Form->input('body', ['type' => 'textarea', 'rows' => '5', 'cols' => '5']);
echo $this->Form->input('email');
echo $this->Form->button('Save');
echo $this->Form->end();
?>
Don't call newEntity() with an empty array. Inste of
$ccomment = $this->Comments->newEntity($this->request->data);
Do:
$ccomment = $this->Comments->newEntity();
And in in the call to patchEntity() pass the $this->request->data
<div>//login.ctp
<?php echo $this->Form->create('Register'); ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->input('password'); ?>
<?php echo $this->Form->end('Login'); ?>
this is login page of my application.
If i give invalid details or valid details it logged in to home.please help hear..
public function login(){
if($this->Auth->loggedIn()){
$this->redirect(array('action' => 'home'));
}
if($this->request->is('post')){
if ($this->Auth->login($this->request->data)) {
$this->Session->write('Register',$this->request->data);
$this->redirect(array('controller' => 'Registers','action' => 'home'));
} else {
$this->Session->setFlash(__('Username or password is incorrect'));
}
}
}
this is RegistersController page..
change your form as below --
<?php echo $this->Form->create('Register'); ?>
<?php echo $this->Form->input('User.username'); ?>
<?php echo $this->Form->input('User.password'); ?>
<?php echo $this->Form->end('Login'); ?>
and check that in your AUTH component you have setted the model name to 'User' and fields mapped to Auth component settings -- and in your login function
$this->Session->write('Register',$this->request->data); this line is not needed any more.
go on below link for detail --
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html
Hii i am trying to multiple update in single table
Below i am describing controller, view coding
In controller
public function multiEdit($oid,$cid){
$this->set('oid',$oid);
$this->set('cid',$cid);
$this->set('oid',$oid);
$this->set('cid',$cid);
$item = $this->Item->find('all',array('conditions' => array('Item.order_id' => $oid,'Item.visible'=>true)));
if($this->request->is('post') || $this->request->is('put')){
if($this->Item->saveAll($this->data)){
$this->Session->setFlash('Item Information has been updated',true);
$this->redirect(array('action' =>'index',$oid,$cid));
}else{
$this->Session->setFlash('Unable to update Item information',true);
}
}
if(!$this->request->data){
$this->request->data = $item;
}
}
In view
<?php echo $this->Form->create('Item');?>
<?php foreach ($this->data as $i => $item): ?>
<?php
echo $this->Form->hidden("Item.$i.id", array('value' => $item['Item']['id']));
echo $this->Form->input("Item.$i.name", array('value' => $item['Item']['name']));
echo $this->Form->hidden("Item.$i.code", array('value' => $item['Item']['code']));
echo $this->Form->hidden("Item.$i.qnty", array('value' => $item['Item']['qnty']));
echo $this->Form->hidden("Item.$i.price", array('value' => $item['Item']['price']));
echo $this->Form->input("Item.$i.sent", array('value' => $item['Item']['sent']));
echo $this->Form->hidden("Item.$i.ac_sent", array('value' => $item['Item']['ac_sent']));
echo $this->Form->hidden("Item.$i.visible", array('value' => $item['Item']['visible']));?
<?php endforeach; echo $this->Form->end('Save Item') ?>