Welcome Guest, Not a member yet? Register   Sign In
anchor and MVC
#1

[eluser]Ajaxian64[/eluser]
Hy

I have 2 views view1.php and view2.php
in view1.php I would like to address a specific anchor located in view2.php

In html I would like to have something like :
in view2.php <a name="myTarget">...</a>

And In View1.php
Code:
<a href="xxxx/???#myTarget">more here</a>

And I don't know what to put here :down:
xxx is my controller which is intended to give data to view2.php So I must use it.
But what is the syntax for saying that I want to address my anchor ?
If I write xxx/#myTarget it means parameter for controller. And then, how can I handle this in my controller ?

Thanks
#2

[eluser]Ajaxian64[/eluser]
Do not hesitate to tell me if my question is stupid.
Maybe I missed something.
But honestly I don't know how to achieve this simple stuff.
#3

[eluser]titoneo[/eluser]
IF YOU WANT JUMP TO ANOTHER PAGE:
suppose the name of your controller is Mytargetcontroller:

Code:
&lt;?php

class Mytargetcontroller extends Controller{


    function action1(){
        //do something here if you want
        
        $this->load->view("view1");    
    }
    
    function action2($param){
        //do something here if you want
        
        $this->load->view("view2");    
    }

}

And in your view1.php have something like this:
Code:
.....
<a href="/mytargetcontroller/action2/xxx">more here</a>
.....


Analize the href url inside 'a':

mytargetcontroller -> is the name of your controller
action2 -> is the name of your method
xxx-> is the first param of your method

And you can put more params if you want:

Code:
<a href="/mysimplecontroller/action2/xxx/yyy/zzz">more here</a>


with this modification in the controller:

Code:
function action2($param1, $param2, $param3){
        //do something here if you want
        
        $this->load->view("view2");    
}

IF YOU WANT MAKE AJAX REQUEST:

Replace # and insert / in order to separate the params when you do the request:

Code:
<a href="/mytargetcontroller/action2#params..">more here</a> //no
<a href="/mytargetcontroller/action2/param1/param2/..."> //yes

or do with post method and receive data like this in the controller (the controller will not receive url params!):
Code:
function action2(){
        //do something here if you want

        $param1 = $this->input->post("param1");
        $this->load->view("view2");    
    }
Wink
#4

[eluser]Ajaxian64[/eluser]
Thanks titoneo for your reply,
My intend is not really JUST loading another page but alsoto scroll to the specified anchor in the new page (to display the new page starting at the anchor).
exactly the same behaviour as (in pure HTML):
in page1 there is
Code:
<a href='page2.html#myAnchor'>more info</a>
in page2, somewhere in the page (for instance at the end)
Code:
<h2 name='myAnchor'>more info on this topic</h2>
When the page2 is loaded, the page is displayed automatically at the anchor (myAnchor)
And I don't know how to achieve this with CI
----
I know that in my controller I should have something like you described, but I don't know how to pass to the view the fact that it must display not at the begining but at the anchor position.
Code:
<h2 name='myAnchor'>more info on this topic</h2>
#5

[eluser]Ajaxian64[/eluser]
There is a discuss about this but :
+ I would prefer to avoid javascript
+ I don't understand the redirect solution, because in this case you come to the same mechanism, the controller receive
Code:
redirect('you/should/be/here/#anchor');
and I don't know how to clearly said into the controller how to handle this "parameter" (the anchor's name)

Do you see any solutions without using javascript ?




Theme © iAndrew 2016 - Forum software by © MyBB