I am passing two query result inside view but only one result work.please give me a solution - codeigniter-3

I am passing two result inside view but only one result is working.
public function editCustomer(){
$custId = $this->uri->segment(3);
$desResult['designation'] = $this->ecd->hrmDesignationId();
$result['editDetails'] = $this->ecd->editDetails($custId);
$this->load->view('editCustomerDetails',$result,$desResult);
}

The second argument of the $this->load->view() method should be an array.
The proper way to do this is to build your array before calling the load method:
$result['designation'] = $this->ecd->hrmDesignationId();
$result['editDetails'] = $this->ecd->editDetails($custId);
$this->load->view('editCustomerDetails',$result);
The two variables will then be available in your view. You can write them down to check :
var_dump($designation);
var_dump($editDetails);

Related

How to write to an Element in a Set?

With arrays you can use a subscript to access Array Elements directly. You can read or write to them. With Sets I am not sure of a way to write its Elements.
For example, if I access a set element matching a condition I'm only able to read the element. It is passed by copy and I can't therefore write to the original.
For example:
columns.first(
where: {
$0.header.last == Character(String(i))
}
)?.cells.append(value: addValue)
// ERROR: Cannot use mutating member on immutable value: function call returns immutable value
You can't just change things inside a set, because of how a (hash) set works. Changing them would possibly change their hash value, making the set into an invalid state.
Therefore, you would have to take the thing you want to change out of the set, change it, then put it back.
if var thing = columns.first(
where: {
$0.header.last == Character(String(i))
}) {
columns.remove(thing)
thing.cells.append(value: addValue)
columns.insert(thing)
}
If the == operator on Column doesn't care about cells (i.e. adding cells to a column doesn't suddenly make two originally equal columns unequal and vice versa), then you could use update instead:
if var thing = columns.first(
where: {
$0.header.last == Character(String(i))
}) {
thing.cells.append(value: addValue)
columns.update(thing)
}
As you can see, it's quite a lot of work, so maybe sets aren't a suitable data structure to use in this situation. Have you considered using an array instead? :)
private var _columns: [Column]
public var columns : [Column] {
get { _columns }
set { _columns = Array(Set(newValue)) }
// or any other way to remove duplicate as described here: https://stackoverflow.com/questions/25738817/removing-duplicate-elements-from-an-array-in-swift
}
You are getting the error because columns might be a set of struct. So columns.first will give you an immutable value. If you were to use a class, you will get a mutable result from columns.first and your code will work as expected.
Otherwise, you will have to do as explained by #Sweeper in his answer.

Change variable value with what is in a function

I have values in my function that I want to put into the labels that I have linked to my viewController. I tried to do currentTempLabel.text = result.main.temp but it did not want to do that in the function. So I moved that to the viewDidLoad and made some variables, var temp: String = "". In my function I have it set the variable to the value that I get from the API in that function but it doesn't set it to the value. When I run the app it just comes up with the default values that I put into it.
Right now I have the values printing to the console but I need the to go to the actual app and display. This is probably something very simple but I just can't figure it out.
In the function I have:
self.temp = String(result.main.temp)
And in viewDidLoad I have:
currentTempLabel.text = temp
In my mind this should work but not in Swift's mind.
The API to get the weather data works asynchronously. Assign the value to the label in the completion handler on the main thread
DispatchQueue.main.async {
self.currentTempLabel.text = String(result.main.temp)
}

Combining two element locators [duplicate]

I am trying to keep my pageObjects in Protractor as clean as possible, but have run up against some behavior in selecting sub-elements.
This works:
var parent = element(by.css('.parent-class'));
parent.element(by.css('.child-class')).getText();
However this does not:
var parent = element(by.css('.parent-class'));
var child = element(by.css('.child-class'));
parent.child.getText();
Is there someway to do something like the second example? I'd rather not have the element locators spread throughout the methods on my pageObjects, but it seems thats the only way to locate subelements?
In actual application I have a long list of cards, from which I filter down to just the one I am looking for. I then want to do things with subelements of the card.
You could use the locator() function to get the locator of the child element and use it to find a child of the parent. This is similar to the solution you provided in your comment, but allows you to define all properties on your page object as web elements instead of a mix of elements and locators:
var parent = element(by.css('.parent-class'));
var child = element(by.css('.child-class'));
parent.element(child.locator()).getText();
I have a lot of the following code:
var parent = element(by.css('.parent-class'));
var child = parent.element(by.css('.child-class'));
child.getText();
But as far as I understood you have a lot of children and you don't want to list all the variants.
Additionally to Nathan Thompson answer you can have a helper function in page object to find subelement:
function getCard(parent, child) { // Or getChild()
return element(by.css(parent)).element(by.css(child));
}
function getCardText(parent, child) { // Or getChildText
return getCard(parent, child).getText();
}
So then you can just write in spec:
expect(cardPage.getCardText('.parent-class', '.child-class')).toBe('...');
I wanted to mention that using 5.2.2 version this implementation is bit different.
To get actual selector value you must use following code
let selector = child.locator().value
This is because locator returns an object which contains selector and other properties, but in this case, you only need selector.
here is what is returned by method locator()
name(name) {
return By.css('*[name="' + escapeCss(name) + '"]');
}
{ using: 'css selector', value: '.child-class' }
Here is how it should be implemented now.
var parent = element(by.css('.parent-class'));
var child = element(by.css('.child-class'));
parent.element(child.locator().value).getText();
//short hand
var parent = $('.parent-class');
var child = $('.child-class')
parent.$(child.locator().value).getText();

Protractor Chained Elements by Using Variables?

I am trying to keep my pageObjects in Protractor as clean as possible, but have run up against some behavior in selecting sub-elements.
This works:
var parent = element(by.css('.parent-class'));
parent.element(by.css('.child-class')).getText();
However this does not:
var parent = element(by.css('.parent-class'));
var child = element(by.css('.child-class'));
parent.child.getText();
Is there someway to do something like the second example? I'd rather not have the element locators spread throughout the methods on my pageObjects, but it seems thats the only way to locate subelements?
In actual application I have a long list of cards, from which I filter down to just the one I am looking for. I then want to do things with subelements of the card.
You could use the locator() function to get the locator of the child element and use it to find a child of the parent. This is similar to the solution you provided in your comment, but allows you to define all properties on your page object as web elements instead of a mix of elements and locators:
var parent = element(by.css('.parent-class'));
var child = element(by.css('.child-class'));
parent.element(child.locator()).getText();
I have a lot of the following code:
var parent = element(by.css('.parent-class'));
var child = parent.element(by.css('.child-class'));
child.getText();
But as far as I understood you have a lot of children and you don't want to list all the variants.
Additionally to Nathan Thompson answer you can have a helper function in page object to find subelement:
function getCard(parent, child) { // Or getChild()
return element(by.css(parent)).element(by.css(child));
}
function getCardText(parent, child) { // Or getChildText
return getCard(parent, child).getText();
}
So then you can just write in spec:
expect(cardPage.getCardText('.parent-class', '.child-class')).toBe('...');
I wanted to mention that using 5.2.2 version this implementation is bit different.
To get actual selector value you must use following code
let selector = child.locator().value
This is because locator returns an object which contains selector and other properties, but in this case, you only need selector.
here is what is returned by method locator()
name(name) {
return By.css('*[name="' + escapeCss(name) + '"]');
}
{ using: 'css selector', value: '.child-class' }
Here is how it should be implemented now.
var parent = element(by.css('.parent-class'));
var child = element(by.css('.child-class'));
parent.element(child.locator().value).getText();
//short hand
var parent = $('.parent-class');
var child = $('.child-class')
parent.$(child.locator().value).getText();

In C#, how do I get a distinct value from an IEnumerable using LINQ?

I have an IEnumerable variable that I want to extract a distinct value from. I know all the entries in the rows of the list have the same value, I just need to get that value.
The method returns an IEnumerable.
The row in the IEnumerable is defined as:
QuoteCovId
AdditionalInterestId
AdditionalInterestsAffiliateId
AdditionalInterestsLastName
AdditionalInterestsBusinessAddrLine1
AdditionalInterestsBusinessCity
AdditionalInterestsBusinessState
AdditionalInterestsBusinessZip
Sampel of code:
IadditionalInterestData = AdditionalInterestData.GetAdditionalInterests(MasterPkgID, Requestor);
// Using linq.
var quotes = from ai in IadditionalInterestData
select Distinct(ai.QuoteCovId);
// Iterate thru to get the 1 value.
foreach (int QuoteCovId in quotes)
{
quoteID = QuoteCovId;
}
var quoteId = AdditionalInterestData.GetAdditionalInterests(MasterPkgID, Requestor)
.FirstOrDefault().Select(f => f.QuoteCovId);
But that method:
AdditionalInterestData.GetAdditionalInterests(MasterPkgID, Requestor);
returns me an IEnumerable which I will use further in my application. Which is what I need.
So how will your suggestion still give me that IEnumerable and give me the quote value which happens to be the same in the collection?
var quoteId = AdditionalInterestData.GetAdditionalInterests(MasterPkgID, Requestor).FirstOrDefault().Select(f => f.QuoteCovId);
Also, I just added your line of code as is and I get an error statement.