cakephp select field of relationed elements for show in a view - cakephp

I have this in cakephp, I try choose the field to be displayed in the combobox when creating related data in cake php.
<?php echo $this->Form->create('Round'); ?>
<fieldset>
<legend><?php echo __('Add Round'); ?></legend>
<?php
echo $this->Form->input('description');
echo $this->Form->input('text_marked');
echo $this->Form->input('project_id');
echo $this->Form->input('User');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
I try select one project with project_title, in the table project, not by 'project_id'. Title are not unique but is more descriptive than id. Can I do this in cake php?

The answer was easy,Thus we choose the field to display in the other views that are associated. it was put:
public $displayField = 'titte'
in the Round model.

Related

Drupal7 Solr Search | Views | No Results Template (?)

I'm using Drupal 7's Solr Search Views module to display my search results.
However, when there are no results, there is no message that displays and i can't figure out how to set one and/or where to find the setting that displays it.
Can anyone help with this?
Thanks.
I've gotten the result I wanted by modifying the 'views-view--viewName.tpl.php' like so:
Original (was not showing anything when $empty or no results):
<?php if ($rows): ?>
<?php print $rows; ?>
<?php elseif ($empty): ?>
<?php print $empty; ?>
<?php endif; ?>
New (shows custom message when no results are found):
<?php if ($rows): ?>
<?php print $rows; ?>
<?php else: ?>
<h2>There are no results for this term. Please refine your search.</h2>
<?php endif; ?>
The big difference is the change from 'elseif ($empty):' to a simple 'else:'.

How can I use the same form in multiple views

I am using CakePHP 2.4. I have a blog where I can add and edit posts. When I implemented my edit.ctp, I recognized, that I have the same code in the view add.ctp:
<?php
echo $this->Form->create();
echo $this->Form->input('headline');
echo $this->Form->input('text', array('type' => 'textarea');
echo $this->Form->end('Save');
?>
(simplified code)
Regarding CakePHP´s recommendation, I want to keep my code DRY. What is the best way to define the form only one time and use it in both views?
Create a view in the folder Element with the form code
// app/View/Elements/postForm.ctp
<?php
echo $this->Form->create();
echo $this->Form->input('headline');
echo $this->Form->input('text', array('type' => 'textarea');
echo $this->Form->end('Save');
?>
Then include it in your desired views
echo $this->element('postForm');

Cake Bake issue with views using cakephp3.0

I am new to cakephp framework and i am using cakephp3.0 now i used baking concept instead of using scaffolding. After baking it automatically generated all pages based on my tables in database and it generated code in models,controllers and views.Now my question is "if it is possible to change the code in views to change field types (from text box to radio button) according to my requirements."
Please help me.
Thanks in advance
Yes, after you bake your project you can change the fields types. Navigate to the folder where all your views are located, for example: app\View\MyViewName. Baking is a great tool to get something up and running fast. If you have a fairly structured website mostly used for data entry this is a great tool. I used it for simple data entry websites and it has saved me so much typing! Just add some data validation/constraints in the model and you're good to go!
A freshly baked view will look a little something like this:
<div class="MyForm Form">
<?php echo $this->Form->create('MyForm'); ?>
<fieldset>
<legend><?php echo __('Add My Form'); ?></legend>
<?php
echo $this->Form->input('field1');
echo $this->Form->input('field2');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List My Forms'), array('action' => 'index')); ?></li>
</ul>
</div>
Change the input methods to look something like this:
$options = array('Y' => 'Yes', 'N' => 'No');
echo $this->Form->radio('myFields', $options);

formhelper cakephp dont work

I use cakephp 2.3.1 and trying to creat a form with formhelper.
This is my addStudent.ctp :
<?php
$this->Form->create("Test");
$this->Form->input("stuId",array('class'=>'inputField', 'placeholder'=>'SVxxxxxxxx'));
$this->Form->input("stuName",array('class'=>'inputField', 'name'=>'stuName'));
$this->Form->input('submit',array('type'=>'submit'));
$this->Form->end();
?>
I've already add : var $helpers= array('Form'); in AppController.
But it show nothing ? what is the problem here:(
You need to echo the output to the browser. Remember that you are using functions here that return html. But in order for it to be displayed on the page it has to be echo-ed. Try this:
<?php
echo $this->Form->create("Test");
echo $this->Form->input("stuId",array('class'=>'inputField', 'placeholder'=>'SVxxxxxxxx'));
echo $this->Form->input("stuName",array('class'=>'inputField', 'name'=>'stuName'));
echo $this->Form->input('submit',array('type'=>'submit'));
echo $this->Form->end();
?>

Changing table field using 2 different models

I have an IT query system were by users can add their queries, when they add their query the IT department then replies/comments on the query.
How is should work is when the user adds a query it must change the query_type field in the it_queries table to OPEN and when the IT department views the query they reply/comment on it and must change query_type field from OPEN to PENDING then finally when the user has been helped/assisted they should be able to mark the query as closed using a checkbox, that will then change the status from PENDING TO CLOSE.
Not sure if they is a way of setting the constants in the add views and insert in the table.
Obviously i am learning and can someone please guide me on the steps i must take.
Here is my code for the add it_query for the users
<?php echo $this->Form->create('ItQuery'); ?>
<fieldset>
<legend><?php echo __('Add It Query'); ?></legend>
<?php
echo $this->Form->hidden('hr_employee_id',array('value'=>$loggedInId));
echo $this->Form->input('it_query_type_id');
echo $this->Form->input('comment');
echo $this->Form->hidden('status_type', array('value'=>OPEN));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
Here is the code for my comments for IT Department
<?php echo $this->Form->create('ItQueryComment'); ?>
<?php echo __('Add It Query Comment'); ?>
<?php
echo $this->Form->input('it_query_id');
echo $this->Form->input('comment');
echo $this->Form->input('close_query');
?>
<?php echo $this->Form->end(__('Submit')); ?>
Here is the code for my ItQueryComments
public function add() {
if ($this->request->is('post')) {
$this->ItQueryComment->create();
if ($this->ItQueryComment->save($this->request->data)) {
$this->Session->setFlash(__('The it query comment has been saved'));
$this->redirect(array('controller' => 'it_queries','action' => 'view', $this->request->data['ItQueryComment']['it_query_id']));
} else {
$this->Session->setFlash(__('The it query comment could not be saved. Please, try again.'));
}
}
$itQueries = $this->ItQueryComment->ItQuery->find('list');
$hrEmployees = $this->ItQueryComment->HrEmployee->find('list');
$this->set(compact('itQueries', 'hrEmployees'));
}
While saving a comment for a particular Itquery , in your add function of Comments Controller after adding comment to database get its id by using $this->getLastInsertID();
and call function updateAll for Itquery Model and change status of that particular Query to "Pending".

Resources