PHP Undefined Index Notice / Error - zend-framework

A page I have in my app will not display the required text so I checked my Apache error log and I found the following notice/error.
PHP Notice: Undefined index: PetManager_Model_Groomprocedures display.phtml on line 34
It is due to the fact that I'm trying to display a result from a query and it can't seem to obtain this item from my result array.
The situation is I'm querying a booking table that is related to a services table (theses elements display fine) the services table is in turn related to a procedures table(this is the element that will not display).
Can someone tell me where I'm going wrong i.e. my Query or my display code and how can I get this to work.
Query Code from my Display Action
if ($input->isValid()) {
$q = Doctrine_Query::create()
->from('PetManager_Model_Kennelbooking k')
->leftJoin('k.PetManager_Model_Kennelservices s')
->leftJoin('s.PetManager_Model_Groomprocedures g')
->leftJoin('k.PetManager_Model_Clients c')
->leftJoin('k.PetManager_Model_Kennels l')
->where('k.kennelbookingID = ?', $input->id);
if('k.groomingIncluded'==1)
{$q->addWhere('s.groomingGiven=g.groomProceduresID');
}
$result = $q->fetchArray();
if (count($result) == 1) {
$this -> view -> booking = $result[0];
The display code from my phtml file
<td class="key">Grooming Procedure </td>
</tr>
<tr>
<?php if($this->booking['PetManager_Model_Kennelservices']['groomingGiven']==NULL)
echo '<td>'.'There is no grooming procedure associated for this booking'.'</td>';
else echo '<td>'.$this->escape($this->booking['PetManager_Model_Groomprocedures']['groomprocedure']).'</td>';
;?>
</tr>
Many thanks in advance,
Graham

As you can see the index PetManager_Model_Groomprocedures is not defined in the booking-variable.
To see which keys are available do the following in your controller to get a debug output.
echo '<pre>';print_r($result[0]);echo '</pre>';exit;
You will see which keys are available in this array. I guess you are not selecting the wanted row explicitly. You will modify your query this way, that you also do select the wanted row.

Related

How to select specific data in dynamic table using protractor?

I am trying to automate some scenarios using protractor where we need to verify whether the data is updating in dynamic table.
Please find below
HTML Code:
enter image description here
Table in page:
enter image description here
It can be done by verifying that element is present in the DOM with the added Group ID or Group Name.
For Group ID:
element(by.xpath("*//table//tbody//tr//td[1]//p[text()='Amanda Test
Group']")).isDisplayed()
For Group name:
element(by.xpath("*//table//tbody//tr//td[2]//p[text()='Amanda
Group']")).isDisplayed()
I'm assuming you're using Angular2+, yes?
In your HTML Template, you are probably using an *ngFor directive to populate the table dynamically. Add an index to the *ngFor (it's best practices for updating the DOM) in order to add a dynamic id to each element:
<tr *ngFor="let user of user; index as u" id="user-{{u + 1}}">
<td id="userName-{{u + 1}}">
{{user.firstName}} {{user.userName}}<br />
{{user.userName}}
</td>
<td id="userRoles-{{ u + 1 }}">
<span id="role-{{u + 1}}-{{ r + 1 }}" *ngFor="let role of user.roles; index as r">
{{ role.toUpperCase() + ', '}}
</span>
</td>
<!- Omitted code -->
</tr>
In your Page Object:
// Get first user on the table
get firstUser() {
return element(by.id('user-1');
}
// Get a specific user by id
public getUser(index: number) {
return element(by.id(`user-${index}`);
}
// Get all of the attributes for a single user by id
get userAttributes(index: number) {
return element.all(by.id(`user-${index}`);
}
I am not a fan of xpath selectors. Yes, they are faster. But in code that is dynamic or changes frequently, they are the most fragile of selectors. There is no reason your dynamic data cannot have a dynamic ID that clearly identifies each portion of the code you need.
Good luck!

Mootools: get text from clicked link's sibling table node

here's the situation:
| ID | Name | ...
+----+--------+---
| 12 | Henry | ... a whole list of names, ids,&c ...you get the idea
+----+--------+---
| 13 | Julia | ...
+-------------+---
...
all the names are links. when selected, they load the rest of the table for editing by passing the name into a quick mysql query. but since i'm getting dupes, i need to grab the id as well to pass along. i also need it for updating the corrected (and correct!) record.
so, using MooTools, how do i grab the text from the neighbouring sibling when i click the link? hell, even just plain ol' JS will do.
here's the existing function:
function loadRecord(aName) {
console.log("loadRecord called with: "+aName);
user = $('submitterName').value;
id = $('table-id').text; // THIS IS THE PROBLEM RIGHT HERE. >_<
console.log('with user: '+user);
$('recordName').value = aName;
$('addRecordButton').value = 'Update Record';
$('addRecordData').action='_php/updateRecord.php'; // this isn't working either...
var action=$('addRecordData').action;
console.log(action);
checkUserDB(aName,user,id);
}
since there are multiple rows to the table, i can't assign a unique identifier to each ID to any benefit. i'm still stuck trying to pull the table-id's text that relates to the clicked link.
i hope i am clear. any help or illumination would be much appreciated.
TIA crew!
WR!
Here is the solution
HTML
<!--Change your HTML-->
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td>12</td>
<td><a>Henry</a></td>
</tr>
<tr>
<td>13</td>
<td><a>Julia</a></td>
</tr>
</table>
MooTools
window.addEvent('load', function(){
window.addEvent('click:relay(a)', function(event){//Add your selector inside relay
event.preventDefault();
console.log($(this).getParent('td').getPrevious().get('html'));
//Add Your AJAX code here
});
});
Here you are attaching a click event to anchor then selecting
parent(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getParent)
then as you have ID in previous
element(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getPrevious)
you can grab the previous element and get it's HTML
You can check the pen here http://codepen.io/arifmahmudrana/pen/yYQeJX

Yii2-mongodb: how to add database fetched items in dropdown list

I am trying to add the team names(to be fetched from mongoDB) in the form to let user select the form name.
I am not getting how to add the database fetched form names in the dropdown list.
It should search based on organization_id first & then form_name.
what i am doing is this:
<?= $form->field($model1, 'form_name')->dropDownList(ArrayHelper::map(CreateTeam::find(array('organization_id' => Yii::$app->session['organization_id']))->all(), 'form_name')); ?>
It is showing me an error that missing the third argument. What could be the third argument in that case???
I went through issue with fetching record from country collection to serve record in state form
I got solution as below (considering as my state form)
use app\models\Countries;
use yii\helpers\ArrayHelper;
$countries=Countries::find()->all();
$listData=ArrayHelper::map(Countries::find()->all(),function ($model){return (string)$model->_id;},'name');
echo $form->field($model, 'countries_id')->dropDownList($listData, ['prompt'=>'Select...']);
Hope I was able to let you understand !
$collection2 = Yii::$app->mongodb->getCollection('teamdashboard');
$models = $collection2->find(array('organization_id' => Yii::$app- >session['organization_id']));
$items = ArrayHelper::getColumn($models, 'team_name');
return $this->render('teamdashboard', ['model1' => $model1, 'model2' => $model2, 'items' => $items]);
This one works fine for mongodb...
Yes, in ArrayHelper::map() first three parameters are required, so you are definitely calling this method wrong.
Check out official documentation for map().
The second parameter represents the actual values in database (usually they are primary keys), the third - readable text.
Assuming your primary key is id it should be:
$models = CreateTeam::find([
'organization_id' => Yii::$app->session['organization_id'],
])->all();
$items = ArrayHelper::map($models, 'id', 'form_name');
<?= $form->field($model1, 'form_name')->dropDownList($items) ?>

In Yii, how best to POST both search results selection & previously entered form model back to form controller?

To complete a Yii form field, users often need to search for a referenced model record (like searching for a friend's profile in a social app). I'm sure other Yii apps are doing this elegantly. But in my dirty approach, in the search results page, I use a CHtml::submitButton to POST two models back to the form containing:
the "found" record (a user id associated with one of the profiles from the search results)
the previously entered form field contents (relationship characterization fields)
Alternatively, the autocomplete widget works well, but doesn't do the detailed search that I need (e.g. search based on a partial name and city or state or other user profile content).
Alternatively, you'd think that within the search results view I might be able to modify the form member to contain the found record (new friend's user id) and just POST/submit the modified model from the search results page . But for that to work each of the search results in the list needs a unique user id populated in that form field, and I can't figure out how to duplicate the form model before modifying that one member server-side for each of the search results' "submit" or "select" buttons, and it just doesn't seem right to create all those form models.
So what seems to work is to submit two separate models using subforms (within the search results view) , with the submitButton POSTing a model and the extra parameter (user id) separately.
Is there a better way? ...to link to and from a search results page and a form field, retaining already-entered data and populating the searched for field with a selected record from the search results.
Here's controllers/SiteController:
public function actionBefriend() {
$model=new BefriendForm;
if(isset($_POST['BefriendForm'])) {
$model->attributes=$_POST['BefriendForm'];
if ($model->validate()) {
$model->createFriendship();
$this->redirect('Index'); }
else
$er=$model->getErrors(); }
if(isset($_POST['idfriend'])) {
$model->idfriend=$_POST['idfriend']; }
if(isset($model->idfriend)) {
$model->friend_name=Bio::model()->findByPk($model->idfriend)->name; }
$this->render('newFrienship', array('model' =>$model)); // newFriendship is the form view }
Here's controllers/Bio.php (Profile)
public function actionIndex() {
$criteria = new CDbCriteria();
$model=new BefriendForm;
if(isset($_GET['q']))
$q = $_GET['q'];
elseif (isset($_POST['BefriendForm'])) {
$model->attributes=$_POST['BefriendForm'];
$q = $model['friend_name']; }
if(isset($q)) {
$criteria->compare('name', $q, true, 'OR');
$criteria->compare('city', $q, true, 'OR');
$criteria->compare('state', $q, true, 'OR');
$criteria->compare('bio_text', $q, true, 'OR'); }
else
$q = '';
$dataProvider=new CActiveDataProvider('Bio', array('criteria'=>$criteria));
$this->render('index',array('dataProvider'=>$dataProvider, 'q'=>$q, 'model'=>$model )); }
Here's the start of views/site/newFriendship (form view)
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'newFriendship-BefriendForm',
'enableAjaxValidation'=>true,)); ?>
Here's the core of views/bio/index.php (search results index page):
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'viewData'=>array('model'=>$model) )); ?>
Here's the search result row in views/bio/_view.php that links back to BefriendForm (SiteController) that sends the id of the user to populate the friend field in the form (which gets a name from the id):
<form method="POST">
<input type="hidden" name="idfriend" value="<?php echo $data->idfriend ?>" />
// Here's that submit button that I can't get to send both the model
//and the idfriend back to the form to repopulate it
// without manually writing HTML to submit all the fields individually
// or creating 2 subforms to submit together with a signle submitButton.
<?php echo CHtml::submitButton('Befriend', array('submit' => array('site/Befriend'),'model'=$model);
</form>
The best alternative I can see is to imbibe the searcher widget within the form.
Turns out you can just replace the form field containing the primary key with the appropriate value before POSTing back to the NewFriendship form when the user clicks the "Select" or "Befriend" button. So only one model is posted back to the original form from the search results page.
Replace the section from views/bio/_view.php in the question with...
<?php
foreach($model->attributeNames() as $name)
if($name != 'friend_id')
echo CHtml::activeHiddenField($model,$name);
else
echo CHtml::activeHiddenField($model,$name,array('value'=>$data->getPrimaryKey()));
echo CHtml::submitButton('Befriend', array('submit' => array('site/Befriend')));
?>

Help needed formatting Doctrine Query in Zend Framework

Can anyone tell me how to format the query below correctly in my controller.
Currently it gives me nothing in my FilteringSelect. However if I change it to >= I get back all the kennelIDs which is incorrect also but at least I'm getting something.
I've tested that the session variable is set and can confirm that there are kennels with the matching capacity.
// Create autocomplete selection for the service of this booking
public function servkennelAction()
{
$sessionKennelBooking = new Zend_Session_Namespace('sessionKennelBooking');
// disable layout and view rendering
$this->_helper->layout->disableLayout();
$this->getHelper('viewRenderer')->setNoRender(true);
// get list of grooming services for dogs from the table
$qry= Doctrine_Query::create()
->from('PetManager_Model_Kennels k');
//This should be set by default and narrows down the search criteria
if(isset($sessionKennelBooking->numPets)){
$b=(int)$sessionKennelBooking->numPets;
$qry->addWhere('k.capacity = ?','$b');
}
$result=$qry->fetchArray();
//generate and return JSON string using the primary key of the table
$data = new Zend_Dojo_Data('kennelID',$result);
echo $data->toJson();
}
Many thanks in Advance.
Graham
I think that addWhere condition is wrong. It has to be:
$qry->addWhere('k.capacity = ?', $b);
i.e. $b without quotes.