How to get Session data in Codeigniter - codeigniter

Fatal error: Call to Undefined method CI_Session::get_userdata()
in/application/xamp/htdocs/application/models/articles_model.phI
I face a this error; how do I resolve this?

Its not correct method to get session data in code igniter.
To assign vale to session use
$this->session->set_userdata('name',$value);
To fetch value of session use
echo $this->session->userdata('name');
To pass an array
$temp = array('name'=>'John Doe','login'=>1);
$this->session->set_userdata('details',$temp);
To get array session data
print_r($this->session->userdata('details'));
$details = $this->session->userdata('details');
echo $details['name'];

Fatal error: Call to Undefined method CI_Session::get_userdata()
get_userdata() change into userdata()
Because it's the userdata() built-in session function in Codeigniter.
You can't change this

Related

Store Helpers functions in mysql Table Undefined variable $employee_id

I'm working on Laravel and I have functions in the helper. I want to store the functions in the data base (mirgation).
Ex function in the helper :
function PayrollSalary($employee_id, $employor_id)
I can't store the below line when I migrate the database. I have an error message (Undefined variable $employee_id).
DB::table('payroll_model_items')->insert(array(
'code'=>"BaseSal",
'name'=>"Base Salary",
'value'=>"<div>{{PayrollSalary($employee_id, $employor_id)}}</div>",
'sequence'=>"0000101",
'created_at'=>date('Y-m-d H:m:s'),
'updated_at'=>date('Y-m-d H:m:s')
));
Can anyone help?
Thank you

Result set error if no records are returned by db - codiegniter

Severity: Notice
Message: Undefined offset: 0
Message: Trying to get property of non-object
When records are found in the db there are no errors, but the above error is given when no result is returned by the query.
How to solve it?
public function filessearch($id,$type){
$this->db->from('files');
$this->db->like('FTitle',$id);
$this->db->where('FBlock','UnBlock');
$this->db->where('FFullType',$type);
$this->db->limit(50);
$this->db->order_by('FID','DESC');
$this->db->group_by('FTitle');
$query=$this->db->get();
return $query->result();
}
Where is giving you that error ain't in the code you showed us, but I can identify and guess the issue.
Somewhere in your code you do something like this:
$fileResults = $this->your_model->filessearch($someId, $someType);
echo $fileResults[0]->some_column;
And what happens is that if no result is returned from database the index zero [0] doesn't exists.
Validate first if the array is not empty.
if(count($fileResults) > 0)
echo $fileResults[0]->some_column;

JFactory::getUser($id) not working

I'm trying to use JFactory::getUser() to get the name and username of a certain user but it returns error!
For example when I write this:
echo JFactory::getUser(645)->name;
it returns this error:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to a member function load() on a non-object in D:\wamp\www\libraries\joomla\user\user.php on line 888
but it works fine when I enter my own id there, and returns my name!
More info:
I use this function in a field type file, and I already used that in another field type file in the same site and in the same way without any problem! The difference between these is that: I'm using this in a custom component, but that was used in the com_categories component.
pcrikos is right you have to create an instance of the User object first. Once you have done that you call can then object property in an echo statement. Also note that passing no integer (numerical value) to the method will leverage the current user session as the user state and that user id will be used.
//This will instance the user object of the current user state
$user = JFactory::getUser();
//This will instance the user object for a given user defined by passed id aregument
$user = JFactory::getUser(1);
Once you have that object instanced you can call any of the method properties to get the data you seek.
echo $user->name;
echo $user->username;
echo $user->email;
Also note that if you are seeking to get the users ACL's it actually returns as an array. You can see the full object properties and examples here: http://docs.joomla.org/Accessing_the_current_user_object
I thing you should first instantiate a user object.
$user = JFactory::getUser(646);
and then if it is not null (i.e. he/she exists)
do an
echo $user->name;

Get parameters from another component

I have two custom components that reference an external database. In component1 I set the parameters necessary to connect to that external DB.
Is there I way that I can use the parameter set in component1 within component2?
my code within my model in component2:
$app = JFactory::getApplication();
$params = $app->getParams('com_component1');
advises me of a fatal error:
Fatal error: Call to undefined method JApplicationAdministrator::getParams() in /var/www....
Should I just stop being lazy and redefine the same parameters in component2, or is there a reasonable solution?
Try using the following code.
$params = JComponentHelper::getParams('com_component1');
$test = $params->get('param_name');
To get parameters, you need to use JComponentHelper, not JFactory.

How to call magento module in custom page?

I have added this:
echo $this->getLayout()->createBlock('core/template')->setTemplate('sales/order/history.phtml')->toHtml();
to mypage.phtml, but it is giving
Fatal error: Call to a member function getSize() on a non-object in C:\xampp\htdocs\puckerimages_cvs\app\design\frontend\default\pucker\template\sales\order\history.phtml on line 41
Can anybody tell me how to call core module controller in custom pages
I dont know exactly what you were tried to do..Controller is nothing but your url segment.
If you want get controller from Url use the following code,
Mage::app()->getRequest()->getControllerName();
Mage::app()->getRequest()->getActionName();
Mage::app()->getRequest()->getRouteName();
Mage::app()->getRequest()->getModuleName();
If you want get collection of data from your Module use the following code,
Mage::getModel('groupname/classname');
or
Mage::getSingleton('groupname/classname');
Example
$collection = Mage::getModel('module/model_name')->getCollection()
->addAttributeToSort('order', 'ASC')
->addAttributeToSort('last_name', 'ASC')
->addAttributeToSort('first_name', 'ASC')
;
try this
instead of "core/template" use "sales/order_history"
<?php echo $this->getLayout()->createBlock('sales/order_history')->setTemplate('sales/order/history.phtml')->toHtml();?>
hope this help you

Resources