我在layout.phtml中有一组js文件,但我不需要一次加载所有js文件,我需要在各个页面上加载。我怎么能这样做。
<?php echo $this->headScript()
->appendFile($this->basePath() . '/js/jquery.js')
->appendFile($this->basePath() . '/js/jquery-1.9.1.min.js')
->appendFile($this->basePath() . '/js/jquery-ui.js')
->appendFile($this->basePath() . '/js/bootstrap.min.js')
->appendFile($this->basePath() . '/plugins/underscore/underscore-min.js')
->appendFile($this->basePath() . '/plugins/moment/moment.js')
->appendFile($this->basePath() . '/plugins/pace/pace.min.js')
->appendFile($this->basePath() . '/plugins/wysiwyg/bootstrap3-wysihtml5.all.min.js')
->appendFile($this->basePath() . '/plugins/validator/bootstrapValidator.min.js')
->appendFile($this->basePath() . '/plugins/clock-picker/clockpicker.js')
->appendFile($this->basePath() . '/plugins/bootstrap-calendar/js/calendar.js')
->appendFile($this->basePath() . '/plugins/Chart.js-master/Chart.js')
->appendFile($this->basePath() . '/js/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 9',))
->appendFile($this->basePath() . '/js/html5shiv.js', 'text/javascript', array('conditional' => 'lt IE 9',))
->appendFile($this->basePath() . '/js/main.js')
->appendFile($this->basePath() . '/js/profile.js')
->appendFile($this->basePath() . '/js/profile_12.js')
->appendFile($this->basePath() . '/js/profile_2.js')
->appendFile($this->basePath() . '/js/profile_users_medical_events.js')
->appendFile($this->basePath() . '/plugins/cropper/cropper.min.js')
->appendFile($this->basePath() . '/js/profile-photo.js')
->appendFile($this->basePath() . '/js/select2.min.js')
->appendFile($this->basePath() . '/js/selectize.min.js')
->appendFile($this->basePath() . '/js/new_appointment.js')
->appendFile($this->basePath() . '/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js')
->appendFile($this->basePath() . '/js/users_profile_chart.js')
->appendFile($this->basePath() . '/js/livestamp.min.js')
->appendFile($this->basePath() . '/js/res.js')
->appendFile($this->basePath() . '/js/rec.js')
->appendFile($this->basePath() . '/js/settings.js')
; ?>
我需要的只是加载所需的js文件。
答案 0 :(得分:0)
就像你在布局中所做的那样 - 你可以在视图中调用帮助器。
<?php $this->headScript()->appendFile($this->basePath() . 'my.js') ?>
<h2>Some Heading</h2>
但是不要回应它 - 它将被附加到你的布局中的那个列表中并放在那里。