I tried several ways to apply the .css and .js files to the view php file. (1) The first way is as shown below:
<head>
<meta charset="UTF-8" />
<?php echo html::meta('viewport', 'width=980'); ?>
<title>A-TRACK Tutoring</title>
<?php echo html::link('http://fonts.googleapis.com/css?family=Open+Sans:300,400,700',
'stylesheet','text/css', FALSE);?>
<?php echo html::link('media/css/atrack.css',
'stylesheet','text/css', FALSE, 'all');?>
</head>
......
</html>
(2) The second way is as shown below:
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=980" />
<title>A-TRACK Tutoring</title>
<?php
if(isset($css)){
foreach($css as $type => $file){
?>
<link type='text/css' href='<?php echo $file ?>' rel='stylesheet' />
<?php
}}
?>
......
</head>
and in the index action of the controller
public function action_index()
{
$view = View::factory('singleanswer/index');
$view->css = array(
'normal' => 'media/css/atrack.css',
'normal' => 'http://fonts.googleapis.com/css?family=Open+Sans:300,400,700',
);
// Render the view
$this->response->body($view);
}
} // End Welcome
Neither of them works. Does anyone know the reason ? Thanks.
In example 2, you are writing over the atrack.css value by using the same key twice in the array.
Change your controller like this:
And update your view to this: