- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- putThemeContent
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
putJsReady Method
The putJsReady
method will put (injected) javascript code into document ready block of javascript.
This method can be called in controller or in a view as well.
This method only work if getJsReady method called inside document ready block in a View Layout.
Basic Usage
Here is the basic usage for putJsReady
method from SENE_Controller class.
$this->putJsReady(string $content_location[, array $data]): $this
Parameters
This method has 1 required parameter and 1 optional parameter.
$content_location
The $content_location
value will be referred to a file name under app/view/THEME/
.
This value also can contain path prefix of subdirectory before the filename.
Learn more about javascript specific view component .
$data
The $data
value is an array that contained one or more array key value(s).
Example Usage
Here is the basic example for putJsReady
method.
class Home extends SENE_Controller
{
public function __construct()
{
parent::__construct();
$this->setTheme('front');
}
public function index()
{
...
$this->putJsReady('home/home_bottom',$data);
...
}
}
So, the front
theme and home_bottom.php
layout should be existed on the directory structure.
app/
└── view/
└── front/
├── home/
└── home_bottom.php
Full Example with $data usage
Here is the full example for putJsReady
method using $data and its content.
app/
└── controller/
| └── home.php
└── view/
└── front/
├── home/
| ├── home.php
| └── home_bottom.php
└── page/
└── col-1.php
Here is the content of home.php
controller file.
class Home extends SENE_Controller
{
public function __construct()
{
parent::__construct();
$this->setTheme('front');
}
public function index()
{
$data = array();
$data['admin_name'] = 'Daeng';
$this->putJsReady('home/home_bottom',$data);
...
}
}
Here is the content of col-1.php
layout file.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<script>
$(document).ready(function(e){
<?php $this->getJsReady(); ?>
});
</script>
</body>
</html>
Here is the content of home_bottom.php
embedded javascript file.
alert('<?php echo $admin_name?>');
The $data
variable that passed into putJsContent
method, has been extracted into native variable depending on key name of array.
In this case, the $data['admin_name']
converted into $admin_name
if called inside home_bottom.php
file.