Welcome Guest, Not a member yet? Register   Sign In
access variable and method
#1

[eluser]ranjitbd[/eluser]
Code:
// i can load a helper file by following code

    $this->load->helper('needed_variable');

//or in the autoload.php file by following code
    
    $autoload['helper'] = array('needed_variable');

// suppose $month is a array type variable and get_day() is a method
// exist in needed_variable_helper.php file which is written below:

    $month = array();
    $month["01"] = "January";
    $month["02"] = "February";
    $month["03"] = "March";
    $month["04"] = "April";
    $month["05"] = "May";
    $month["06"] = "June";
    $month["07"] = "July";
    $month["08"] = "August";
    $month["09"] = "September";
    $month["10"] = "October";
    $month["11"] = "November";
    $month["12"] = "December";


    function get_day()
        {
                $day = array();
            $day[0] = "Monday";
        $day[1] = "Tuesday";
        $day[2] = "Wednesday";
        $day[3] = "Thursday";
        $day[4] = "Friday";
        $day[5] = "Saturday";
        $day[6] = "Sunday";
        $day[7] = "Daily";

        return $day;
        }



// i access the get_day() function in a combo box in a view file
// holiday_tab.php like following way
    
    




<span>Day</span><br />
<span>
        <select name="day" id="day">
         <option value="all">Any</option>
        &lt;?php
        $day = get_day();
    foreach($day as $key => $value)
    {?&gt;
        <option value="&lt;?php echo $key;?&gt;">&lt;?php echo $value ;?&gt;</option>
         &lt;?php } ?&gt;
      </select>
</span>

// how can i access $month in another combo box like above mentioned way
//my code is below which not working properly

<span>Month</span><br />
<span>
        <select name="month" id="month">
         <option value="all">Any</option>
        &lt;?php
        // what will be the code here.....................
    foreach($month as $key => $value)
    {?&gt;
        <option value="&lt;?php echo $key;?&gt;">&lt;?php echo $value ;?&gt;</option>
         &lt;?php } ?&gt;
      </select>
</span>


// i cant set a function for the $month. Like get_month().
//Please help? thanx in advance
#2

[eluser]bretticus[/eluser]
[quote author="ranjitbd" date="1253899345"]

i cant set a function for the $month. Like get_month().
Please help? thanx in advance

[/quote]

Why can't you make a function that returns your month array?
#3

[eluser]ranjitbd[/eluser]
Code:
// a lot of variable is already declared and used in many applications. so its not possible //to change the needed_variable.php file.
// there is no way to access a variable from a helper file????????
#4

[eluser]n0xie[/eluser]
Why not add a function to whatever file you have where you declare you month array and do something like this?
Code:
function get_month()
{
    return $month;
}
#5

[eluser]ranjitbd[/eluser]
Code:
// i know very well that using a function i can access any variable. but i came to
// know that isn't it possible to acces a variable from a helper file without any
// function.




Theme © iAndrew 2016 - Forum software by © MyBB