how to create 2 variable session in Codeigniter - codeigniter

How to Create 2 variable session
I have create but for $se not show

I think your after something like Multiple session but question unclear
Examples
Backend
$session_vals1 = array(
'some_data' => 1
);
$this->session->set_userdata('backend', $session_vals1);
To access
$session_vals1_data = $this->session->userdata('backend');
echo $session_vals1_data['some_data'];
Frontend
$session_vals2 = array(
'some_data' => 2
);
$this->session->set_userdata('frontend', $session_vals1);
To access
$session_vals1_data = $this->session->userdata('frontend');
echo $session_vals1_data['some_data'];

Related

Laravel how to update multiple id values

Laravel how to update multiple id valus in table
print_r($test); exit();
Array ( [0] => 185 [1] => 216 )
$report = Test::find($test);
$report->status = "A";
$report->save();
Test::whereIn('id', $test)->update(['status' => "A"]);
Good luck

Laravel differences linux and windows hosting

This is very strange: On Windows these functions with exactly the same databases works greats, but when I upload the project to Linux the pageinfo() function returns null. Of course the first thing I thought was that this has to do with case sensitivity, but all seems well formatted...
In my Page Model:
public function pageinfo() {
return $this->hasMany('App\Models\PageToElement', 'page_id');
}
(The Model PageToElement is exactly called like this)
In my controller:
$this->info = Page::find($page->page_id);
$meta = $this->info->pageinfo->where('element_id', 1)->first();
On Windows this nicely returns array:
App\Models\PageToElement Object (
[attributes:protected] => Array(
[id] => 1
[page_id] => 1
[element_id] => 1
[element_parent_id] => 0
[parent_id] => 0
[sorting] => 0
[is_active] => 1
[created_at] => 2015-12-07 10:00:03
[updated_at] => 2015-12-07 10:00:03
)
)
But on Linux, the response is null
What am I overlooking?
After some research, I came to the conclusion that $meta = $this->page->pageinfo->where('element_id', 1)->first(); returns null on the Linux server. But when I do $meta = $this->page->pageinfo; I do get more than one item in return. When I then do $meta = $this->page->pageinfo->first(); it returns one. So I think somehow the where('element_id', 1) is not working for Linux.
But what do you know, $meta = $this->page->pageinfo->where('element_id', '1')->first(); works! element_id is an integer, so why does it need quotes???
But what do you know, $meta = $this->page->pageinfo->where('element_id', '1')->first(); works! But then again not on Windows.
So I wounded up adding an extra line $id = 1; and parsing that in the query.
Strange workaround though

Codeigniter echo session Multidimensional Array variable

Okay im using codeigniter and i got a session where i want to echo [user_id], i can see its an "Multidimensional Array", but i cant seem to get it right...
This is the print_r from all session userdata:
Array (
[session_id] => b7e721332248
[ip_address] => ::1
[user_agent] => Mozilla/5.0
[last_activity] => 1409104940
[user_data] => [name] => 2 [uniq] => 2
[flexi_auth] => Array ( [user_identifier] => mail.com [user_id] => 2 [admin] => 1
[group] => Array ( [3] => Master Admin )
[privileges] => Array ( )
[logged_in_via_password] => 1
[login_session_token] => 11017021313jhbjh1h2j3b213mab913269d95 ) )
if i type:
print_r($this->session->all_userdata()); // i will get all
echo $this->session->userdata('uniq'); //returns 2
echo $this->session->userdata('user_id'); //returns nothing(THIS IS THE PROBLEM)
Ive tried something like this:
$this->session->userdata(1,1); //1,1 would be array 2 and number 2 which would be user_id
Is it because i can only print out if I loop through them somehow?
You're trying to call the data directly, if you're want to access user_data or flexi_auth you need to assign the data to a variable then target it since they're arrays.
$session_data = $this->session->all_userdata();
echo $session_data['user_data']['uniq']; // 2
$user_data = $this->session->userdata('user_data');
echo $user_data['uniq']; /// 2
$flexi_auth = $this->session->userdata('flexi_auth');
echo $flexi_auth['user_id']; /// 2
If you're trying to target a string directly
echo $this->session->userdata('last_activity');
You can simply access user name stored in session like this
echo $this->session->userdata['user_data']['name'];
Be sure you have some userdata in session or use like this to avoid any errors
echo #$this->session->userdata['user_data']['name'];
adding # does not generate any errors. hope you got the answer you were looking for.

how to sum column value using group by collection in magento(USING MAGENTO STANDARD)

my table is like this and my collection is
$testmodel=Mage::getModel(test/p1)->getCollection();
my database table is below.
id cat_id rate p_id
1 1 4 1
2 1 2 1
3 1 3 2
4 2 5 3
5 2 3 1
and i want output like this in magento using collection
cat_id rate count_category
1 9 3
2 8 2
i found my PROBLEM correct code is below
$testmodel = Mage::getModel('test/p1')
->getCollection()
->addFieldToSelect('rate')
->addFieldToSelect('cat_id');
$testmodel ->getSelect()
->columns('SUM(rate) as total,COUNT(*) AS countCategory')
->group('cat_id');
if you use mysql4 as this model resource class then go to
Model/Mysql4/P1/Collection.php
here you need to add function
public function addGroupByCatId(){
$subSelect = clone $this->getSelect();
$CountsubSelect = clone $this->getSelect();
$subSelect->reset()
->from(array('rev' => 'youtable', 'SUM( rev.rate)')
->where('main_table.cat_id = rev.cat_id');
$CountsubSelect->reset()
->from(array('countrev' => 'youtable'),'COUNT(countrev.cat_id)')
->where('main_table.cat_id = countrev.cat_id');
$this->getSelect()
->join(
array('r' => 'youtable'),
'main_table.id = r.id',
array(
'review_sum' => new Zend_Db_Expr(sprintf('(%s)', $subSelect)),
'count_category' => new Zend_Db_Expr(sprintf('(%s)', $CountsubSelect)),
))
->group('main_table.cat_id');
return $this;
}
OR: Resouce as resource model then goto
if you use mysql4 as this model resource class then go to
Model/Resource/P1/Collection.php
here you need to add function
public function addGroupByCatId(){
$subSelect = clone $this->getSelect();
$CountsubSelect = clone $this->getSelect();
$subSelect->reset()
->from(array('rev' => 'youtable', 'SUM( rev.rate)')
->where('main_table.cat_id = rev.cat_id');
$CountsubSelect->reset()
->from(array('countrev' => 'youtable'),'COUNT(countrev.cat_id)')
->where('main_table.cat_id = countrev.cat_id');
$this->getSelect()
->join(
array('r' => 'youtable'),
'main_table.id = r.id',
array(
'review_sum' => new Zend_Db_Expr(sprintf('(%s)', $subSelect)),
'count_category' => new Zend_Db_Expr(sprintf('(%s)', $CountsubSelect)),
))
->group('main_table.cat_id');
return $this;
}
and final you get
$testmodel=Mage::getModel(test/p1)->getCollection();
$testmodel->addGroupByCatId();

CodeIgniter ActiveRecord adding a random id field

$updatedOrder = array(
'ship_status' => 'shipped',
'shipped_carrier' => (string)$selectedShipper->shipper->name,
'base_rate' => (float)$selectedShipper->rate,
'discount_rate' => (float)$selectedShipper->rate,
'tracking_number' => '123',
);
$this->orders_m->where('id', $tmpOrder->id)
->update('orders', $updatedOrder);
This yields the following SQL query: UPDATE default_orders SET ship_status = 'shipped', shipped_carrier = 'UPS Next Day Air', base_rate = 22.85, discount_rate = 22.85, tracking_number = '123' WHERE id = '1' AND id = 'orders'
Where did that last bit come from? id='orders'?
Just make sure that $tmpOrder->id is a variable and not an array.
var_dump($tmpOrder->id);
Maybe there is an error somewhere where you are getting the $tmpOrder and it returns an array for that.

Resources