phpactiverecord if confition - if-statement

i want to ask something related with php activerecord
here'se my code
public function validate()
{
$log = Login::find(1);
$login = new Login(array(
'id' => 1,
'user' => $_POST['user'],
'pass' => $_POST['pass']
));
if ($this->user = $log->user AND $this->pass = $log->pass | $log->user = $this->user AND $log->pass = $this->pass)
{
APP::redirect('dashboard.index');
}else{
APP::redirect('dashboard.login');
}
}
i wonder why my code always redirect to dahsboard.index although the value from input form and database are different. is there something i missed? and english isn’t my first language, so please excuse any mistakes. thanks before.

You seem to have confused = (assignment) with == (comparison). So you'd get a lot of 'TRUE' in that if.

Related

react native giftedchat can not edit message text

I want to edit a message, but it's only updated when i changed this message _id. Can someone provide me how to do it, here is my code:
const onSend = useCallback((messagesToSend = []) => {
if(editMessage != null){
setEditMessage()
const m = messagesToSend[0]
const newMessages = [...messages]
const index = newMessages.findIndex(mes => mes._id === editMessage._id);
console.log('index: ', index)
if(index > -1){
newMessages[index].text = m.text // => ***i only edit the text***
// newMessages[index]._id = uuid.v4() => ***this working if changed _id***
console.log('newMessages', newMessages[index]) // => ***new message changed it's text but the bubble not change when re-render***
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
setMessage(newMessages)
}
}else{
setReplyMessage()
appendMessage(messagesToSend)
}
})
It looks like you're using useCallback without a dependency array. This means that any dependencies that you rely on will be memoized and won't update when you run the function.
You should add messages, editMessage, and maybe setMessage and appendMessage, to the dependency array. Like so:
const onSend = useCallback(
(messageToSend = []) => etc,
[messages, editMessage, setMessage, appendMessage]);
That's the first thing I would try
ok i found problem, in MessageText the function componentShouldUpdate need modify a bit

Unknown column '' in 'field list MySQLConnector MySQLException

I have a controller class and inside a method of the controller class, I have List Defined as below.
List<TrackedStoreProductsViewModel> currTrackProds = _context.Tracked_Products.Select(p => new TrackedStoreProductsViewModel()
{
TrackedProducts = p,
currentPrice = _context.Store_Products.Where(x => trackedId.Contains(x.product_id)).FirstOrDefault(s => s.product_id == p.product_id).Product_Price_History.OrderByDescending(pr => pr.price_timestamp).Select(pr => pr.price).FirstOrDefault(),
userEmailId = _context.User_Accounts.FirstOrDefault(u => u.account_number == p.account_number).email_id,
userFirstName = _context.User_Info.FirstOrDefault(u => u.account_number == p.account_number).first_name
}
).ToList();
Here I am getting the following exception error
Here the exception error is 'Unknown column 't.Store_Productsproduct_id' in 'field list'.
I checked all the models related to this, set up a breakup point stepped in still couldn't find where it is defined that way? Can someone suggest me an approach I can possibly follow to fix this issue?

Cannot read property 'split' of undefined while testing getting this error

https://www.youtube.com/watch?v=8xDM8U6h9Pw
This is my string I am trying to split that url from = sign. But I am getting error as
TypeError: Cannot read property 'split' of undefined
My code is as follows:
getVideoURL() {
if (this.mealDetails !== null && this.mealDetails !== undefined) {
// let splitUrl = this.mealDetails.strYoutube.split("=");
console.log("strYoutube", this.mealDetails.strYoutube);
this.splitUrl = this.mealDetails.strYoutube.split("=");
const id = this.splitUrl[1];
let url = `https://www.youtube.com/embed/${id}`;
return url;
}
},
please tell me how to resolve that error
Not sure what you intend to do .. but how about this?
const mealDetails = {
strYoutube: "https://www.youtube.com/watch?v=8xDM8U6h9Pw"
}
function getVideoURL(obj) {
if (obj) { // check for non-empty object
const splitUrl = obj.strYoutube.split("=")
return 'https://www.youtube.com/embed/'+splitUrl[1]
}
}
const newUrl = getVideoURL(mealDetails)
console.log(newUrl)
This works great -> https://jsfiddle.net/9r13t4v6/3/
Please use parameters when calling functions ... and to check empty object you can use if(value) ... if it's not empty (=> NaN, null, undefined, 0, false) it will eval as true ..
plus you don't have to use that many variables :) try to stick with as many as possible (-> better readability)

How to add hyperlink using templateprocessor (PHPWord Library)

I want to replace email variable into a hyperlink using template processor and I have used two way to solved this issue but didn't work and here is our below code for replacing email variable into hyperlink but when I used setValue or setComplexValue function for replacement value then document is corrupted.
We have tried below two scenarios for adding hyperlink but didn't work for us.
1. First Way
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$textrun = $section->addTextRun();
$textrun->addTextBreak(2);
$section->addLink('mailto:demo1#gmail.com?subject=DEMO','demo1#gmail.com', array('color' => 'FF0000', 'underline' =>
\PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$fullXml = $objWriter->getWriterPart('Document')->write();
$templateProcessor->setValue($var, $this->getBodyBlock($fullXml));
2. Second Way
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$convertResult = 'demo1#gmail.com';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $convertResult, false,false);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$fullXml = $objWriter->getWriterPart('Document')->write();
$templateProcessor->setValue($var, $this->getBodyBlock($fullXml));
protected function getBodyBlock($string) {
if (preg_match('%(?i)(?<=<w:body>)[\s|\S]*?(?=</w:body>)%', $string, $regs)) {
return $regs[0];
} else {
return '';
}
}
Please help us thank in advance.

How to fetch data from cursor array in facebook From ads insights api call

While calling getInsights() method,it gives an object.so i want to access some data from it.
Here is the api call
$account->getInsights($fields, $params);
echo '<pre>';print_r($resultArr);die;
it will gives result like
FacebookAds\Cursor Object
(
[response:protected] => FacebookAds\Http\Response Object
(
[request:protected] => FacebookAds\Http\Request Object
(
[client:protected] => FacebookAds\Http\Client Object
(
[requestPrototype:protected] => FacebookAds\Http\Request Object
(
Thanks in advance.
The following should work:
$resultArr = $account->getInsights($fields, $params)[0]->getData();
echo '<pre>';
print_r($resultArr);
die;
If you have more than one object in the cursor, you can just loop over it:
foreach ($account->getInsights($fields, $params) as $obj) {
$resultArr = $obj->getData();
echo '<pre>';
print_r($resultArr);
}
die;
In this case, if you set the implicitFetch option to true by default with:
Cursor::setDefaultUseImplicitFetch(true);
you will be sure you are looping over all the results.
I using this piece of code and It works for me, I hope works for you ...
$adset_insights = $ad_account->getInsights($fields,$params_c);
do {
$adset_insights->fetchAfter();
} while ($adset_insights->getNext());
$adsets = $adset_insights->getArrayCopy(true);
Maybe try:
$insights = $account->getInsights($fields, $params);
$res = $insights->getResponse()->getContent();
and then go for the usual stuff:
print_r($res['data']);
Not sure if my method differs from Angelina's because it's a different area of the SDK or if it's because it's been changed since her answer, but below is the code that works for me, and hopefully will be useful for someone else:
$location_objects = $cursor->getArrayCopy();
$locations = array();
foreach($location_objects as $loc)
{
$locations[] = $loc->getData();
}
return $locations;
Calling getArrayCopy returns an array of AbstractObjects and then calling getData returns an an array of the objects props.