Yii Framework Forum: Javascript In View Not Registered While Renderpartial - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Javascript In View Not Registered While Renderpartial PROBLEM !!! Rate Topic: -----

#1 User is offline   Ziggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 14-August 12

Posted 07 February 2013 - 05:45 AM

I need to build an iFrame content with Yii, so I decided to use "renderPartial" method to skip default layout header.

This is my view file's HEAD section:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />

    <title>My iFrame</title>

    <?php
    $cs = Yii::app()->getClientScript();
    $cs->registerCoreScript('jquery');
    $cs->registerScriptFile(Yii::app()->baseUrl .'/js/jquery.blockUI.js');
    $cs->registerScriptFile(Yii::app()->baseUrl .'/js/jquery.form.js');
    $cs->registerScriptFile(Yii::app()->baseUrl .'/js/jquery.MetaData.js');
    $cs->registerScriptFile(Yii::app()->baseUrl .'/js/jquery.MultiFile.js');
    $cs->registerCssFile(Yii::app()->baseUrl . '/css/main.css');
    $cs->registerCssFile(Yii::app()->baseUrl . '/css/form.css');
    ?>

    <!-- blueprint CSS framework -->
    <link rel="stylesheet" type="text/css" href="/css/screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="/css/print.css" media="print" />
    <!--[if lt IE 8]>
    <link rel="stylesheet" type="text/css" href="/css/ie.css" media="screen, projection" />
    <![endif]-->

</head>


Unfortunately, for whatever reason none of the Javascript/CSS files is registered!
Page source sshows nothing linked!!!

But as soon as I do a test and render full rather than partial - all files are properly registered. But I need partial render not full!

Any idea???
0

#2 User is offline   Luke Jurgs 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 16-October 11
  • Location:Australia

Posted 07 February 2013 - 06:19 AM

Hi Ziggi,

If you look at the API: CController::renderPartial, you'll notice that the fourth parameter is $processOutput, this defaults to false. Process output tells Controller/ClientScript to output the script and link tags that correspond to the registered script files/css.
1

#3 User is offline   Ziggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 14-August 12

Posted 07 February 2013 - 09:55 AM

Bingo !!!

Big thanks!
0

#4 User is offline   pjetr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 20-February 13

Posted 20 February 2013 - 07:21 AM

I've got the same problem, so I didn't start a new topic.

CODE
In my controller:
$this->renderPartial('create',array(
    'model'=>$model,
),true,true);


In my create:
<?php echo $this->renderPartial('_form', array(
    'model'=>$model
), true, true); ?>


In my _form:
$this->widget('ext.CKEditor.CKEditor',array(
     "model"=>$model,
     "attribute"=>'value',
     "editorID"=>$editorID,
 ));


and lastly in my widget:
/** @var $cs CClientScript */
$cs=Yii::app()->clientScript;
$cs->registerScript('CKEditor-replace', 'CKEDITOR.replace(\''.$this->editorID.'\', {customConfig: \'config_educate.js\'});', CClientScript::POS_END);


As you can see, I've set in all my renderPartials $return AND $processOutput to true.
I seem to be stuck.
0

#5 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 20 February 2013 - 07:52 AM

Dear Friend

If I am not wrong it is meant thatif third parameter is true ,it is rendering the view but it is not echoing the view.

so it should be

echo $this->renderPartial('create',array(
    'model'=>$model,
),true,true);


or

$this->renderPartial('create',array(
    'model'=>$model,
),false,true);


Regards.
0

#6 User is offline   pjetr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 20-February 13

Posted 20 February 2013 - 08:05 AM

Thank you for your answer, but it didn't work.

In my widget, it still doesn't register my scripts.
Neither does it when $return is true, and $processOutput is false.
0

#7 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 20 February 2013 - 10:09 AM

Dear Friend

I am sorry about that.

Have you checked the things in firebug? is there any related javscript rendered?

Is there any errors at console?

Then you have got two varable in the view.

$editorID

and
$this->editorID


Do they denote same thing or defined differently.

Would you please try the following code?

$cs->registerScript('CKEditor-replace', 'CKEDITOR.replace("'.$editorID.'", {customConfig: "config_educate.js"});', CClientScript::POS_END);


or
$cs->registerScript('CKEditor-replace', 'CKEDITOR.replace("'.$editorID.'", {customConfig: "config_educate.js"});', CClientScript::POS_BEGIN);


Regards.
0

#8 User is offline   pjetr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 20-February 13

Posted 21 February 2013 - 09:51 AM

I had indeed some major javascript errors that weren't caught.

So my problem was not one of Yii. Thank you very much for guiding me to a solution.
0

#9 User is offline   chinmay2011 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 16-May 13

Posted 24 August 2013 - 02:27 AM

View Postpjetr, on 20 February 2013 - 08:05 AM, said:

Thank you for your answer, but it didn't work.

In my widget, it still doesn't register my scripts.
Neither does it when $return is true, and $processOutput is false.



Dear pjetr,

The third parameter ($return) needs to be false and the fourth Parameter ($processOutput) needs to be set true.

$this->renderPartial('create',array(
'model'=>$model,
),false,true);

So what seenivasan said on Post #5 should work.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users