D
D
des1roer2015-06-01 10:16:52
Yii
des1roer, 2015-06-01 10:16:52

Yii emulate ajaxLink click?

form a tree with

CHtml::ajaxLink(
                                    $text = $rows[$i]['title'], array('req'), $ajaxOptions = array(
                                'type' => 'POST',
                                'update' => '#content',
                                'data' => array('id' => $rows[$i]['id']),
                                    ), $htmlOptions = array(
                                    )
                            ),

controller
public function actionReq()
    {        
        $content = $this->renderPartial('application.views.site.pages.frameset');
    }

frame
$page = $_POST['id']; 
 $page = Page::model()->findByPk($page)->link;    
    echo '
    <iframe id="ifr" src="' . $page . '" align="left" seamless>    
    </iframe>';

so I want to write to the session $_POST['id'], and if it exists, send it to the frame. how to implement it?
UPD
what I want to implement is a simple site tree.
the database has a path to the page (if it is external, such as https://toster.ru)
or to the view (if it is implemented in yii),
respectively, you need to make the transitions as soft as possible for the user (and you also need to hide the url from it) .
thus, on ajaxlink, only content can be painlessly refreshed.
a path with direct links is not true.
and here are two approaches - through ajaxlink we give the element id from the base to the iframe and display it.
but the jamb - when reloading the page on f5, the open items of the tree are reset. The way out is quite simple - to store the path to the menu element in the session.
----
but here's the problem with yii views - there is no desire to display them in a frame. how to resolve such a situation. now I made it through the path to the view, and in the view of the view I set the same layout as the main menu. but then the problem of going back to the tree with the iframe selection, so it is displayed in the same model in which the view

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2015-06-01
@evgenybuckharev

1.CHtml::ajaxLink. If you are forming a list, then it is better not to use CHtml::ajaxLink, because in the end, if you have a lot of elements in the list, then the code will be littered with the same functions in js, which will differ only in $rows[$i]['id' ], it is better to write one function for all links of this list, and pass the $rows[$i]['id'] parameter to the data-id type attribute, or alternatively form a simple link specifying the path in the href attribute, and when clicking send an Ajax request to this link along this path, then there will be no extra dances with $rows[$i]['id'].
2. Requests like $page = Page::model()->findByPk($page)->link; it is better to do it in the controller and not in the form, the MVC principle is violated.
3. To get an answer to your question, can you more accurately form what you need? For example, I realized that you need to check if the value of the link with $_POST['id'] is in the session, and if it is, transfer it to the frame, and if it is not there, then request it, save it to the session and again transfer it to the frame?
As an option:

public function actionReq($id)
    {        
        $model = Page::model()->findByPk($id);
        if ($model === null) {
            throw new CHttpException(404, 'Не найден запрашиваемый элемент.');
        }
        $this->renderPartial('application.views.site.pages.frameset',array('link'=>$model->link));
    }

Тогда путь к этой функции будет ...$this->createUrl('req',array('id'=>$rows[$i]['id']))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question