Welcome Guest, Not a member yet? Register   Sign In
redirect to function when clicking a button
#1

[eluser]echo sara[/eluser]
I have a question, i didnt start my script yet since i'm lost on where to start with this. I want to create a menu and when i click on a tab i want it to go to a function so it can either redirect the page or do a function(run a query).

so for example say the div was the tab how would i redirect it to a different page when its clicked on? and if i wanted it to do a function how would i make that work?

redirecting i can use html <href = direct to function in controller> ; but is that the right method?

<div>
// button
</div>

Any feed back is welcome


Thanks

Sara
#2

[eluser]InsiteFX[/eluser]
Use CodeIgniter's URL Helper anchor tag
Code:
&lt;?php echo anchor(uri segments, text, attributes);?&gt;

This is in the CodeIgniter User Guide under the URL Helper.
You can also pass it an array.

InsiteFX
#3

[eluser]echo sara[/eluser]
Ok so just to be 100% clear would the example below be correct?

lets say main domain is http://localhost/
Lets say i want to go to "menu" Controller and the function "go". say i wanted to pass a variable --&gt; title = "home page"


<td><div id="menu"><a&lt;?php echo anchor('news/local/123', 'My News', 'title="News title"');?&gt;>
css styling/html pics
</a></div></td>


did i do it right?
#4

[eluser]Mirge[/eluser]
http://ellislab.com/codeigniter/user-gui.../urls.html

will help you understand Codeigniter URLs.

Code:
echo anchor('menu/go/home page', 'CSS Styling/HTML Pics');
#5

[eluser]echo sara[/eluser]
wait what you saw before wasn't it. for some odd reason when i had [code] [code] around it; it took off what i actually had. i took it off now it shows the actual script i had.
#6

[eluser]InsiteFX[/eluser]
Code:
&lt;?php
$attributes = array(
    'id' => 'css id',
    'class' => 'css class',
    'title' => 'News title'
);
echo anchor('news/local/123', $mtitle, $attributes);
?&gt;
echo anchor('news/local/param1/param2', $mtitle, $attributes);

// to pass a prameter to the method it would be like this.
controller = news

public function local($param1 = null, $param2 = null)
{
    // your code here!
}

$mtitle can be passed thru the view with $data.

InsiteFX
#7

[eluser]echo sara[/eluser]
ok that makes alot more sense. Quick question what do you use to separate your php from html? Doing this will look very messy and disorganized on most view pages. Any suggestions?
#8

[eluser]Jônatan fróes[/eluser]
Code:
<a href="&lt;?php echo site_url('news/local/123'); ?&gt;">My link</a>




Theme © iAndrew 2016 - Forum software by © MyBB