Welcome Guest, Not a member yet? Register   Sign In
How to make controller print two different things in my html at different part
#21

[eluser]adityajoshi[/eluser]
thanks , you are one of my angel, last time you helped me so much. i will try to work using sessiontomorrow,also i have some issue with login. My login has different codeigniter folder and form has different ci folder, in my login i am redirecting to my form but when i use the dump variable its shows empty array.form and login has different controller and views i wonder where variables are lost
#22

[eluser]adityajoshi[/eluser]
I think in my post it was my mistake, i learn php recently,i think we can not pass the data to another page until its a form data. but thanks for the guidance
#23

[eluser]adityajoshi[/eluser]
I am having problem how to use the value of var_dump from login page in the controller

My login page passes the following variable to controller but i am not still able to use it when i try to use inside the controller



my controller is

<?php
$result = $_POST['username'];
var_dump($_POST);
class Login extends Controller {
public function __construct() {
parent::Controller();

$this->load->helper(array('form','url'));
$this->load->library('form_validation');
$this->load->library('session');
}

public function index() {
$this->load->view('/');
}

public function submit() {

if ($this->_submit_validate() === FALSE) {
$this->session->set_userdata(array('userid'=>$result));
$sess = $this->session->userdata('userid');
echo $sess;
$this->index();
return;
}
$this->session->set_userdata(array('userid'=>$result));


redirect('http://localhost/calendar/add');

}

i am getting error


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: result

Filename: controllers/login.php

Line Number: 24

even if i try to just mere echo $result in side my controller it doesn't recognise it


Any help will be highly appreciated
#24

[eluser]CodeIgniteMe[/eluser]
use
<code>
$result = $_POST['some_element']; ...
global $result;
</code>

but why don't you want to declare $result as a property in your controller?like this

<code>
Class Mycontroller extends CI_Controller{
public $result = $_POST['whatever'];

function somefunction(){
$this->session->set_userdata(array('key'=>$this->result));
}

}
</code>

if you want to always var_dump() on $result, you can always do it inside a function or the constructor:
<code>
function __construct(){
parent::__construct();
var_dump($this->result);
}
</code>
#25

[eluser]adityajoshi[/eluser]
Code:
I am still having problem

public function __construct() {
      parent::Controller();
      global $var;
      $this->load->helper(array(‘form’,‘url’));
      $this->load->library(‘form_validation’);
      $this->load->library(‘session’);
  }

  public function index() {
      $this->load->view(’/’);
    
  }

  public function submit() {
        $var = var_dump($_POST[‘username’]);
        $this->session->set_userdata(array(‘userid’=> $this->var));
        $sess = $this->session->userdata(‘userid’);
        if ($this->_submit_validate() === FALSE) {
          echo $sess;
          $this->index();
          return;
        }
    
      redirect(‘http://localhost/calendar/add’);
    
  }

when i go to calendar add it wont show me the value of userid
but if I assign

public function submit() {
        $var = var_dump($_POST[‘username’]);
        $this->session->set_userdata(array(‘userid’=> “testing”));
        $sess = $this->session->userdata(‘userid’);
        if ($this->_submit_validate() === FALSE) {
          echo $sess;
          $this->index();
          return;
        }
it will show me the value of userid in this page (‘http://localhost/calendar/add’);
this code is in my view page
&lt;?php
$sess = $this->session->userdata(‘userid’);
echo $sess; ?&gt;
#26

[eluser]CodeIgniteMe[/eluser]
You have incorrect usage in your codes. But we will try to fix that.
1. If you plan to use $this->var, then you should (although sometimes not required) declare it as a Class property
Code:
Class MyController extends Controller // because It seems that you are using CI < 2.0
{
public $var; // declare explicitly the class-wide variable $var

function __construct(){
parent::Controller();
}

function submit(){
/* your codes here */
// var_dump() usually is not used to fetch a value, it usually displays the contents or something.
// so use var_dump() most probably on debugging things.
$this->var = $_POST['username']; // assign a value to the class-wide variable $var using the $this namespace
// Notice that we don't add a dollar ($) sign before 'var'
/* your codes there */
}
}

2. the session did not return any value because you have set the 'userid' session to an implicitly declared variable $this->var
* Doing this without doing the 1st step, will dynamically add a new class-wide variable but without any value (because it was used just after it was declared)
#27

[eluser]adityajoshi[/eluser]
brother one more help i need from you, In local host every thing works but when i try to upload my administrator (codeigniter) folder in my hosting
it is not able to find the page
http://whiteroseart.com/
My code igniter folder is storied in administrator folder
http://whiteroseart.com/administrator/


when i load this page it works
http://whiteroseart.com/administrator/


but i click submit the page is suppose to redirect to
http://whiteroseart.com/administrator/bl...ent_insert

it is not able to find the page
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /administrator/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /administrator/index.php
</IfModule>
#28

[eluser]CodeIgniteMe[/eluser]
Check your server if it supports mod_rewrite.

You can check by uploading a simple php page with the following codes:

&lt;?php
phpinfo();
?&gt;

then find the word "rewrite" and should be under the apache enabled modules.




Theme © iAndrew 2016 - Forum software by © MyBB