I get protected array from this
$user_id = Mage::getSingleton('admin/session')->getData('user');
var_dump($user_id);die;
object(Mage_Admin_Model_User)[115]
protected '_eventPrefix' => string 'admin_user' (length=10)
protected '_role' => null
protected '_hasAvailableResources' => boolean true
protected '_eventObject' => string 'object' (length=6)
protected '_resourceName' => string 'admin/user' (length=10)
protected '_resource' => null
protected '_resourceCollectionName' => string 'admin/user_collection' (length=21)
protected '_cacheTag' => boolean false
protected '_dataSaveAllowed' => boolean true
protected '_isObjectNew' => null
protected '_data' =>
array (size=17)
'user_id' => string '1' (length=1)
I want to get 'user_id'.,and tried like that $id = $user_id['_data']['user_id']; but it returns null
Try the following
$userId = Mage::getSingleton('admin/session')->getUser()->getId();
or
$userData = Mage::getSingleton('admin/session')->getUser()->getData();
$userId = $userData['user_id'];
Related
I dont have the same result when i var_dump an array in my controller and in my view. This is my controller:
public function index()
{
$getFestivals = $this->festival_model->getAllFestivals();
if (!empty($getFestivals)) {
foreach ($getFestivals as $festival) {
$countFestivalEdition = $this->festival_model->countFestivalEditionByFestivalID($festival->fID);
$festival->fCountEdition = $countFestivalEdition;
}
}
$this->data['getFestivals'] = $getFestivals;
#var_dump($this->data['getFestivals']);die;
$this->render_layout('festivals/index', $this->data);
}
The var_dump (juste before last line) return me:
0 =>
object(stdClass)[24]
public 'fID' => string '6' (length=1)
public 'fName' => string 'Festival2' (length=17)
public 'fPicture' => string '3df2c152d9dec657380c53b679d0b92b.jpg' (length=36)
public 'fCity' => string 'City2' (length=9)
public 'fCountry' => string 'France' (length=6)
public 'fCountEdition' => int 2
1 =>
object(stdClass)[25]
public 'fID' => string '8' (length=1)
public 'fName' => string 'Festival1' (length=19)
public 'fPicture' => string '73a267e6c047d507b66b3a1ab1fc0059.jpg' (length=36)
public 'fCity' => string 'City1' (length=16)
public 'fCountry' => string 'France' (length=6)
public 'fCountEdition' => int 1
On this var_dump i have my 'fCountEdition'. When i make var_dump on my view, i have this (var_dump($getFestivals);die;):
0 =>
object(stdClass)[24]
public 'fID' => string '6' (length=1)
public 'fName' => string 'Festival2' (length=17)
public 'fPicture' => string '3df2c152d9dec657380c53b679d0b92b.jpg' (length=36)
public 'fCity' => string 'City2' (length=9)
public 'fCountry' => string 'France' (length=6)
1 =>
object(stdClass)[25]
public 'fID' => string '8' (length=1)
public 'fName' => string 'Festival1' (length=19)
public 'fPicture' => string '73a267e6c047d507b66b3a1ab1fc0059.jpg' (length=36)
public 'fCity' => string 'City1' (length=16)
public 'fCountry' => string 'France' (length=6)
Why he dont parse my data fCountEdition ?
For informations, my render_layout look like this:
$this->load->view($view, $this->data);
You may try this simple way to send array to view as give example bellow.
Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$data=$this->db->query("SELECT * FROM table_name");
$result=$data->result_array();
$headerData = array(
"pageTitle" => "Home",
"stylesheet" => array("home.css")
);
$footerData = array(
"jsFiles" => array("home.js")
);
$viewData = array(
"viewName" => "home",
"viewData" => array('result'=>$result),
"headerData" => $headerData,
"footerData" => $footerData
);
//Sendig all Result Data to view by Storing into array as $result
$this->load->view('template',$viewData);
}
View
<?php
var_dump($result);
?>
It's because you're not referencing $getFestivals, instead you are passing the value of it to $festival and trying to assign it a new variable.
Basically, passing the value allows you to 'copy' the array/object/etc without modifying the original.
Referencing the original allows to to modify it directly from within the loop.
Do do it the way you've written the code, you need to reference the original instead.
foreach ($getFestivals as &$festival) { <-- add ampersand before $
$countFestivalEdition = $this->festival_model->countFestivalEditionByFestivalID($festival->fID);
$festival->fCountEdition = $countFestivalEdition;
}
I am using using yii2 to in basic template with MySQL database
Why This code returns an object instead of an array of selected records from Database
when i use var_damp($rooms) the output is seems an object and not an array of selected record in array format;
any body can help
public function actionIndexFiltered()
{
$query = Room::find();
$searchFilter = [
'floor' => ['operator' => '', 'value' => ''],
'room_number' => ['operator' => '', 'value' => ''],
'price_per_day' => ['operator' => '', 'value' => ''],
];
if(isset($_POST['SearchFilter']))
{
$fieldsList = ['floor', 'room_number', 'price_per_day'];
foreach($fieldsList as $field)
{
$fieldOperator = $_POST['SearchFilter'][$field]['operator'];
$fieldValue = $_POST['SearchFilter'][$field]['value'];
$searchFilter[$field] = ['operator' => $fieldOperator, 'value' => $fieldValue];
if( $fieldValue != '' )
{
$temp1=$query->andWhere([$fieldOperator, $field, $fieldValue]);
}
}
}
$room1=$temp1->all();
$rooms = $query;
return $this->render('indexFiltered', [ 'rooms' => $rooms, 'searchFilter' => $searchFilter,'room1'=>$room1 ]);
}
Output is like this and this shows that this code return a query object and not an array of query execution on database ,
so i checked the code using var_dump function the results is that it is returning a object not array
object(yii\db\ActiveQuery)[70]
public 'sql' => null
public 'on' => null
public 'joinWith' => null
public 'select' => null
public 'selectOption' => null
public 'distinct' => null
public 'from' =>
array (size=1)
0 => string 'room' (length=4)
public 'groupBy' => null
public 'join' => null
public 'having' => null
public 'union' => null
public 'params' =>
array (size=0)
empty
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
public 'where' =>
array (size=3)
0 => string '=' (length=1)
1 => string 'room_number' (length=11)
2 => string '3' (length=1)
public 'limit' => null
public 'offset' => null
public 'orderBy' => null
public 'indexBy' => null
public 'emulateExecution' => boolean false
public 'modelClass' => string 'app\models\Room' (length=15)
public 'with' => null
public 'asArray' => null
public 'multiple' => null
public 'primaryModel' => null
public 'link' => null
public 'via' => null
public 'inverseOf' => null
This code return an a dataProvider .. alias the code for get models /active record
$query = Room::find();
for obtain the all the models you can use
$roomModels= Room::find()->all();
in this the result is a collection of obejct (models) of class Room
if you need an array you can use
$roomArray = Room::find()->asArray()->all();
In your code $temp1 is the same as $query. andWhere() method returns $this which means that
$temp1 = $query->andWhere([$fieldOperator, $field, $fieldValue]);
makes $temp1 to be the same as $query which is object of yii\db\ActiveQuery.
Now you are calling this:
$room1 = $temp1->all(); // the same as $room1 = $query->all();
and this holds array of Room objects while
$rooms = $query;
is just another unnecessary assignment because $rooms is the same as $query which is object of yii\db\ActiveQuery.
Finally i found the reason for this problem is that
I must call asArray() member function of ActiveRecord class to generate an array output
$room1=$temp1->all(); will changed to $room1=$temp1->asArray()->all();
Ok, so I have an array of objects created in my controller
$displayRooms[$room] = $this->getNextEvent($events, $room);
return view('schedule')->with(['displayRooms' => $displayRooms]);
Then in my view, I am able to iterate over the array and get the $room and $events
#foreach ($displayRooms as $room => $events)
{{ var_dump($events) }}
#endforeach
The var_dump($events) produces
/home/vagrant/sites/google-cal/storage/framework/views/96faa8d8afe2e0f07db5d96a536009499a3c48a5.php:22:
object(stdClass)[176]
public 'available' => boolean false
public 'room' => string 'Room 318' (length=8)
public 'summary' => string 'Chem 3090 Himmeldirk' (length=20)
public 'startTime' => string '12:00pm' (length=7)
public 'endTime' => string '3:00pm' (length=6)
public 'startDay' => string '03/21/17' (length=8)
public 'endDay' => string '03/21/17' (length=8)
/home/vagrant/sites/google-cal/storage/framework/views/96faa8d8afe2e0f07db5d96a536009499a3c48a5.php:22:null
/home/vagrant/sites/google-cal/storage/framework/views/96faa8d8afe2e0f07db5d96a536009499a3c48a5.php:22:null
/home/vagrant/sites/google-cal/storage/framework/views/96faa8d8afe2e0f07db5d96a536009499a3c48a5.php:22:
object(stdClass)[226]
public 'available' => boolean false
public 'room' => string 'Room 513 (Voinovich Room)' (length=25)
public 'summary' => string 'Reynolds' (length=8)
public 'startTime' => string '1:00pm' (length=6)
public 'endTime' => string '3:00pm' (length=6)
public 'startDay' => string '03/21/17' (length=8)
public 'endDay' => string '03/21/17' (length=8)
My question is how can I iterate over the events object in Blade in order to access the properties of the object, so that I may pass them to a partial view?
If I'm understanding what you are asking (and your data structure) properly, then this should work. You can iterate the array of event objects to access each one individually, and then iterate each individual one to access each individual property / value. This code should be nested within your first foreach (replace the dump with it).
#foreach($events as $event)
#foreach ($event as $prop => $value)
// do whatever with prop / values
#endforeach
#endforeach
If you don't need to access each property / value of the object one at a time, then I would recommend this instead.
#foreach($events as $event)
// do whatever with each event
{{ var_dump($event->available) }}
#endforeach
I have the following query generated by laravel:
insert into [web_cmdelt] (
[id],
[list_num],
[is_main],
[published_at],
[list_title],
[artdes],
[unitdes],
[unitprix],
[detail_qty],
[catdes],
[souscatdes],
[art_origine],
[art_label],
[art_transport],
[art_culture],
[art_annexe5],
[art_annexe6],
[artcateg],
[artsouscateg],
[hash]
) values (4728, 1004, 1, 2015-02-12 10:33:02.000, COMPANY NAME, AUBERGINE "P"ESP , Kg, 5.80, , LEGUMES, LEGUMES, ESP, , , , , , 1, 7, 1619328673)
from this object:
object(Ronin\Entities\OrderItem)[230]
protected 'connection' => string 'webcmd' (length=6)
protected 'table' => string 'web_cmdelt' (length=10)
protected 'primaryKey' => string 'cmdelt_id' (length=9)
public 'timestamps' => boolean false
protected 'fillable' =>
array (size=0)
empty
protected 'perPage' => int 15
public 'incrementing' => boolean true
protected 'attributes' =>
array (size=20)
'id' => string '4728' (length=4)
'list_num' => string '1004' (length=4)
'is_main' => string '1' (length=1)
'published_at' => string '2015-02-12 10:33:02.000' (length=23)
'list_title' => string 'COMPANY NAME' (length=18)
'artdes' => string 'AUBERGINE "P"ESP ' (length=17)
'unitdes' => string 'Kg' (length=2)
'unitprix' => string '5.80' (length=4)
'detail_qty' => null
'catdes' => string 'LEGUMES' (length=7)
'souscatdes' => string 'LEGUMES' (length=7)
'art_origine' => string 'ESP' (length=3)
'art_label' => null
'art_transport' => null
'art_culture' => null
'art_annexe5' => null
'art_annexe6' => null
'artcateg' => string '1' (length=1)
'artsouscateg' => string '7' (length=1)
'hash' => string '1619328673' (length=10)
...
The problem is that SQL Server raise this error (sql editor error):
ErrorCode: -2146232060
[.Net SqlClient Data Provider]
Number: 102, Class: 15, State: 1, Line: 1
ErrorMessage: Incorrect syntax near '10'.
I see many problems here:
the date isn't quoted, so the space between date and time breaks the query
same for any other string field (why they aren't quoted ??)
the NULL values are inserted as '' (but without quotes)
Can someone point me to the right direction ?
This raw format should fix the issue.
DB::insert("insert into users (id, name) values (1,'Kamaro Lambert')");
As title, I have a library function $this->foo->bar(). How can I pass $upload_data array to $this->foo->bar() param?
I have this in my controller
$upload_data = $this->upload->data();
//$upload_data['file_name']
$this->foo->bar($upload_data);
Then I have this in my library
public function bar($arr){
$config['source_name'] = //How can I use $arr['file_name'] in here
}
And I got this error
Message: Illegal string offset 'file_name'
var_dump($upload_data)
array (size=14)
'file_name' => string '1358459309.JPG' (length=14)
'file_type' => string 'image/jpeg' (length=10)
'file_path' => string 'C:/wamp/www/foldering/assets/img/uploaded_photos/' (length=49)
'full_path' => string 'C:/wamp/www/foldering/assets/img/uploaded_photos/1358459309.JPG' (length=63)
'raw_name' => string '1358459309' (length=10)
'orig_name' => string '1358459309.JPG' (length=14)
'client_name' => string '200X CNY1.JPG' (length=13)
'file_ext' => string '.JPG' (length=4)
'file_size' => float 30.87
'is_image' => boolean true
'image_width' => int 640
'image_height' => int 480
'image_type' => string 'jpeg' (length=4)
'image_size_str' => string 'width="640" height="480"' (length=24)
My mistake, issue comes from another function