Answer the question
In order to leave comments, you need to log in
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(
)
),
public function actionReq()
{
$content = $this->renderPartial('application.views.site.pages.frameset');
}
$page = $_POST['id'];
$page = Page::model()->findByPk($page)->link;
echo '
<iframe id="ifr" src="' . $page . '" align="left" seamless>
</iframe>';
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question