Welcome Guest, Not a member yet? Register   Sign In
Need some help
#1

[eluser]Unknown[/eluser]
hi, i have no idea why this controller isn't working as I expected :gulp:
it s a simple class with an attribute and 4 methods: set(), get(), index (), and the constructor.

Code:
<?php
class Text extends Controller {
    var $a="foo";
    function text()
    {
    parent::Controller();
    $this->load->helper(array('form', 'url'));
    }
//______________________________________________________
    function index()
    {
    $this->load->view('formtext');
    }
//_____________________________________________________
    function set()
{
    $this->a="Value";
    echo 'Variable set';
}
//______________________________________________________
  
  function get()
{
  echo '<br>'.'a='.$this->a;
}
}
?&gt;


The view is:

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt; Title &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
        &lt;?echo anchor('text/set', 'Set ( a ) ');echo '<br>'; ?&gt;
    &lt;?echo anchor('text/get', 'Get ( a )!');echo '<br>'; ?&gt;
&lt;/body&gt;
&lt;/html&gt;

Once both of the links from the view are clicked, I was expecting
to be displayed
Quote:a="Value"
, but instead of this, i
get for the "a" attribute the same value as it was at the begining.
It's the first time i'm using php classes, so I must be very wrong about smth..

Anyway, the reason I'm testing this is because
I only need a way to transmit a parameter from
one function to another inside a controller
(can t be that hard ;-P !!!), maybe a global variable?

Thx in advance
#2

[eluser]Craig A Rodway[/eluser]
If you need to store data in that way (between requests) you will need to use sessions. Your current method is not working because the variable only lasts for each request that you make to /text/set.

Also, your first anchor doesn't go to /text/set - just /text/.
#3

[eluser]Unknown[/eluser]
Thanks, it worked with sessions Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB