I am not actually login in to the page.But when i click on the services on index page for more services , show logout button instead of login.Please provide solution for this issue.
Controller:
public function more_services($serviceid)
{
$data = $this->data;
$this->load->helper(array('form','url'));
$id=$this->session->userdata('id');
$this->load->model('realpropertiesmodel');
$data['service']=$this->realpropertiesmodel->getServicesbyID($serviceid);
$this->smarty->view('service/service_viewdetails.tpl',$data);
}
public function logout()
{
$this->session->sess_destroy();
$data = $this->data;
redirect("realestate/index" ,'refresh');
}
In the view i add the following code:
[~if $id==''~]
[~include file="common/realestate_header.tpl"~]
[~else~]
[~include file="home/realestate_header.tpl"~]
[~/if~]
But i got the same error when add this much f code.Please provide solution for this issue
your id variable might be false so your check with "" might fail.
First solution:
Change the id variable as -1 if no login information is present:
$this->load->helper(array('form','url'));
$id= $this->session->userdata('id');
$id = ($id) ? $id : -1;
$this->load->model('realpropertiesmodel');
And then check for:
[~if $id!=-1~]
Second solution
Directly check for false:
[~if $id==false~]
Related
I have a function that I use to get the user id of Auth component. It works fine without use return json_encode. The problem is that I need this works with json_encode because I get values from ajax request.
Using json_encode it always return null to id and I can't understand why does it occur. The problem is with the function indexAjax() below.
How could I use $this->Auth->user("id") with json_encode and it not return null ?
Trying.
//using $this->set it works fine
public function index() {
$id = $this->Auth->user("id");
$empresas = $this->Empresa->find('all', array(
'fields'=>array("id", "nomeFantasia", "cnpj",
"telefone1", "telefone2", "celular", "aberto"),
'conditions'=>array("users_id = "=> $id)
));
debug($id) or die;
//$this->set(compact('empresas'));
}
//with json_encode always return null
public function indexAjax() {
$this->autoRender = false;
$id = $this->Auth->user("id");
$empresas = $this->Empresa->find('all', array(
'fields'=>array("id", "nomeFantasia", "cnpj",
"telefone1", "telefone2", "celular", "aberto"),
'conditions'=>array("users_id = "=> $id)
));
return json_encode($id);
}
solved the problem. My solution was when user make login I get the user id and write in session so when I need this id I get from session directly and not from AuthComponent.
It works.
I have a question. I have a route on my site where I put in session an variable like this:
public function userCaptcha(){
$_SESSION['isFacebookRegistration'] = 0;
}
Now I have another route witch render a view :
public function index(){
$this->session = $_SESSION;
return $this->render('template/index.twig');
}
In the index template I do :
{{ dump(session.isFacebookRegistration) }}
{% set session = session|merge({'isFacebookRegistration' : 3}) %}
I access the first route : userCaptcha() one time but the route index() 2 times, normally I need to see the first time 0 and the second 3. But I see only the 0 for 2 times. Can you help me please? The idea is to show for first time 0 for the rest 3. Thx in advance
You cannot set a PHP var on Twig side. Every time your view is reloaded, changes you made to your variable will be lost. You can try something like this:
public function userCaptcha(){
$_SESSION['isFacebookRegistration'] = 0;
}
public function index(){
if (isset($_SESSION['flag'])) {
$_SESSION['isFacebookRegistration'] = 3;
}
$_SESSION['flag'] = true;
$this->session = $_SESSION;
return $this->render('template/index.twig');
}
This way, executing index() for first time won't change isFacebookRegistration value, but will set a flag. Next time, the conditial will be true an isFacebookRegistration will change.
I am using codeigniter. I used session variable to store a id in a function and get the stored value in another function. I have a controller file which is given below:
public function select_service($id)
{
$this->load->library('session');
$this->session->unset_userdata('employee');
$this->session->set_userdata('employee', ['total'=>$id]);
// $id = $this->uri->segment(4);
$data['service'] = $this->add_service_model->get_services();
$data['main_content'] = 'admin/service_limitation/service_view';
$this->load->view('includes/template', $data);
}
In the above code I get the id from a form and store in the session variable
public function services()
{
//here i need to get the session variable employee['total']
$id = $this->uri->segment(5);
$data_to_store=array('employee_id'=>$id,'service_id'=>$this->input->post("services"));
$this->add_service_model->save($data_to_store);
$data['addservice'] = $this->add_service_model->get_addservices();
$data['main_content'] = 'admin/service_limitation/newview';
$this->load->view('includes/template', $data);
}
In this function service I need to retrieve the stored value. both functions are in same controller. can some one help me with the code?
Manuall
Auto load the session library. This way the session is always loaded.
when setting the id do: $this->session->set_userdata('employee', $id);
when you want to get that id user $id = $this->session->userdata('employee');
please help me, this is simple thing but I don't know why this still keep error for an hour,
on my view I've got :
<a href="admin/editProduct?idd=$id">
on my controller that directed from above :
public function editProduct(){
$data["id"] = $_GET['idd'];
$data["produk"] = $this->model_get->get_data_list(2);
//this below doesn't work either, i just want to past the parameter to my model
//$data["produk"] = $this->model_get->get_data_list($_GET['idd']);
$this->adminHeader();
$this->load->view("adminPages/editProduct", $data);
$this->adminFooter();
}
I can not use the array id. It keeps telling me undefined variable idd.
I don't know what to do anymore, please anyone help!
I am using Codeigniter framework
Change your view as:
<a href="admin/editProduct/<?php echo $id;?>">
And in the controller, either get the id as parameter,
public function editProduct($id) {
}
or as uri segment
public function editProduct() {
$id = $this->uri->segment(3);
}
Change your link (in view) with this
<a href="admin/editProduct/$id">
And change your controller as
public function editProduct($id) {
}
Then user $id inside your controller
Make the href link as follows:
...
And edit the controller like this:
public function editProduct($id){
...
$this->model_get->get_data_list($id);
}
Where $id will be the passed $id.
make
try this this works fine
public function editProduct()
{
$id=$this->uri->segment(3);
$data["produk"] = $this->model_get->get_data_list($id);
$this->adminHeader();
$this->load->view("adminPages/editProduct", $data);
$this->adminFooter();
}
I'm using delete_user hook to make some action (call another function) before the user is deleted.
This is part of my code:
function delete_user( $user_id )
{
include('sso_functions.php');
global $wpdb;
$user_obj = get_userdata( $user_id );
$email = $user_obj->user_email;
$login = array_values(login($email));
$login_err = $login[1];
$cookie = $login[0];
if($login_err == 0)
{
//....
}
else
{
//...
}
}
add_action( 'delete_user', 'delete_user' );
Login() function is declared in sso_settings.php file.
If I try to delete only one user is working good.
But if I try to delete 2 users - login() function is called and first user is deleted from Wordpress, but after that I get a php error that function login() is redeclared.
If I use include_once('sso_functions.php') instead of include('sso_function.php'). I don't receive the error and users are deleted from Wordpress but function Login() is not called for second user.
Any idea how can I solve this?
Thanks!
The wordrpess shows correct error message. Instead of using include('sso_functions.php'); line try using it
if(!function_exists('login')){
include('sso_functions.php');
}
I am not sure but i think delete_user is already a function. Just try replacing the name from delete_user to something else. Something like
add_action( 'delete_user', 'wp_delete_user' );
And also dont forget to change the name of the function. Its always better if you use the your plugin name as a prefix. Same goes with the function login, add a prefix to it, so it core functions are not mixed with custom created functions.
$array = array(1,2,3,4); //array of user that need to delete
foreach($array as $userid)
{
delete_user( $userid );
}