Error in CGridView Yii, what i need to do, what fix it:
Parse error: syntax error, unexpected T_STRING in Z:\home\kaskad\www\framework\base\CComponent.php(612) : eval()'d code on line 1
'date'=>array(
'value' => $this->rus_date("j F Y H:i ", $data->date),
),
You can reference the controller in the value expression as follows using $this->grid->controller:
'date'=>array(
'value' => '$this->grid->controller->rus_date("j F Y H:i ", $data->date)',
),
Related
I do have the following output in the form of an array
$fetchSubFormDetailData = $this->PMSDS11FetchSubFormDetailTrait($request);
echo 'Data Submitted' ;
print_r($fetchSubFormDetailData);
The result shown because of print_r is as under
Data SubmittedArray
(
[LineId] => 10
[IncomeTo] => 500000.00
)
Now I want to extract IncomeTo from this array into a variable in this controller for validations. I tried using the following ways
$IncomeTo = $fetchSubFormDetailData[0]->IncomeTo;
I am keep on getting the following error in laravel8.
"message": "Undefined array key 0",
"exception": "ErrorException",
How can I extract the value (500000.00) of IncomeTo element from this array in my $IncomeTo variable?
Any help will be appreciated.
This should work
$IncomeTo = $fetchSubFormDetailData['IncomeTo'];
I am trying to select the user_id of all posts whos id is the current index in the while loop and whose vote is 1 and turn it into a numerical array .
But,it keeps giving me this error:
Illuminate \ Database \ QueryException (HY093)
SQLSTATE[HY093]: Invalid parameter number (SQL: select `user_id` from `laravellikecomment_likes` where (`item_id` = 1 and `vote` = ?))
I dunno what to do now.Here is my code(part of it):
$db='laravellikecomment_likes';
$allposts= DB::table($db)->where('vote','!=',0)->get()->pluck('user_id');
$allposts = $allposts->toArray();
$tn=count($allposts);
$ai=0;
$user=Auth::id();
while ($ai <= $tn) {
$recclist=array();
$current=array_keys($allposts,$ai);
$id=1;
$wl=DB::table($db)->where(function ($query) use ($current, $id) {
$query->where('item_id', '=', $current);
$query->where('vote','=',$id);
})->pluck('user_id');
The error thrown has to do with your query
$wl=DB::table($db)->where(function ($query) use ($current, $id) {
$query->where('item_id', '=', $current); # This line is the culprit
$query->where('vote','=',$id);
})->pluck('user_id');
The error thrown, SQLSTATE[HY093]: Invalid Parameter number hints a parameter is wrong. In this case, you're trying to use an array where the Query Builder expects an integer or a string.
If you want to use an array, use whereIn instead of where, like so:
$wl=DB::table($db)->where(function ($query) use ($current, $id) {
$query->whereIn('item_id', $current); # Use whereIn to deal with arrays
$query->where('vote', '=', $id);
})->pluck('user_id');
I have a view that shows an associated array of Revenues. I have made a collection in the controller to isolate two variables that I need to add together and display as currency.
public function view($id = null)
{
$annualOperatingBudget = $this->AnnualOperatingBudgets->get($id, [
'contain' => ['Azinstitutions', 'BudgetExpenses', 'BudgetExpenses.ExpenseTitles', 'BudgetRevenues', 'BudgetRevenues.RevenueTitles']
]);
$collection = new Collection($annualOperatingBudget->budget_revenues);
$revenuesGroup1 = $collection->match(['revenue_title.revenue_group' => 1 ]);
$revenuesGroup2 = $collection->match(['revenue_title.revenue_group' => 2 ]);
$tuitionAndFees = $collection->match(['revenue_title.revenue_title' => 'Tuition and Fees']);
$lessScholarshipAllowance = $collection->match(['revenue_title.revenue_title' => '- less Scholarship Allowance']);
$this->set(compact('annualOperatingBudget', $annualOperatingBudget,'revenuesGroup1', 'revenuesGroup2', 'tuitionAndFees', 'lessScholarshipAllowance'));
}
I am able to see the variables with the debug kit:
annualOperatingBudget (array)
revenuesGroup1 (array)
revenuesGroup2 (array)
tuitionAndFees (array)
4 (App\Model\Entity\BudgetRevenue)
id 5
annual_operating_budget_id 1
revenue 1278
revenue_title_id 5
revenue_title (array)
lessScholarshipAllowance (array)
5 (App\Model\Entity\BudgetRevenue)
id 6
annual_operating_budget_id 1
revenue -257
revenue_title_id 6
revenue_title (array)
I would like to add the two 'revenue' s together
I tried:
<?= $this->Number->currency(
($tuitionAndFees->revenue) + ($lessScholarShipAllowance->revenue),
'USD', ['places' => 1])
?>
But I get several errors:
Notice (8): Undefined property: Cake\Collection\Iterator\FilterIterator::$revenue [ROOT\plugins\Twit\src\Template\AnnualOperatingBudgets\view.ctp, line 49]
Notice (8): Undefined variable: lessScholarShipAllowance [ROOT\plugins\Twit\src\Template\AnnualOperatingBudgets\view.ctp, line 49]
Notice (8): Trying to get property of non-object [ROOT\plugins\Twit\src\Template\AnnualOperatingBudgets\view.ctp, line 49]
You have to iterate the $tuitionAndFees and the $lessScholarShipAllowance before trying to get the revenue property. Something like this:
foreach($tuitionAndFees as $tuitionAndFee){
echo $tuitionAndFee->revenue
}
If all you need in the view is the total of all tuition and fees, you can use
$tuitionAndFees = $collection
->match(['revenue_title.revenue_title' => 'Tuition and Fees'])
->sumOf('revenue');
This will return just the sum of the matched items. Do something similar for $lessScholarShipAllowance, and then in your view, simply
$this->Number->currency($tuitionAndFees + $lessScholarShipAllowance,
'USD', ['places' => 1])
I have a Sale model, that contains a property_id FK to Property model.
On Property model, there is a field office_id.
The Sale controller contains a partial _search view that I am using to try filter via the office_id.
In search function, I first set the relations to find():
$query = sale::find()->with([
'property',
'listerSaleStaff',
'listerSaleStaff.staff',
'sellerSaleStaff',
'sellerSaleStaff.staff',
]);
The filter clause:
$query->andFilterWhere(['=', 'property.office_id', $params['SaleSearch']['office']]);
where $params['SaleSearch']['office'] does in fact contain the correct office_id
I'm getting PDOException:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'property.office_id' in 'where clause'
The SQL being executed was: SELECT COUNT(*) FROM `sale` WHERE ((`settle_date` >= '2016-07-03') AND (`settle_date` <= '2016-07-31')) AND (`property`.`office_id` = '5')
Error Info: Array
(
[0] => 42S22
[1] => 1054
[2] => Unknown column 'property.office_id' in 'where clause'
Property model does contain relationship:
public function getOffice()
{
return $this->hasOne(Office::className(), ['office_id' => 'office_id']);
}
What am i missing ?
I think you should set the join for search
$query->joinWith(['office' => function ($q) use ($params['SaleSearch']['office']]) {
$q->andFilterWhere(['=', 'property.office_id', $params['SaleSearch']['office']]);
}]);
I have the following SQL
SELECT i_id AS "entity_id", "entity_1" AS "type"
FROM tbl_extensions WHERE ext = 50
which returns me the result and an additional column "type" with the value "entity_1"
to gain the same with Zend_Db I've tried:
$db->fetchAll($db->select()
->from('tbl_extensions',
array('entity_id' => 'i_id',
'type' => 'entity_1'))
->where('ext = ?', 50)));
But I have the following error:
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tbl_extensions.type' in 'field list'
It looks like Zend tries to find a column instead of creating it within the result.
Could anyone help me with it?
easiest solution would be to use Zend_Db_Expr.
$db->fetchAll($db->select()
->from('tbl_extensions',
array(
'entity_id' => 'i_id',
new Zend_Db_Expr('"entity_1" AS "type"'),
)
)
->where('ext = ?', 50));