- 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
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Get First Method
The get_first method is a part of the query builder which is useful for pulling single results from the query builder that has been compiled.
This method will only return maximum 1 row result.
Basic Usage
Here is the basic usage get_first method from $db property on SENE_Model class.
$this->db->get_first([string $result_type="" [, bool $is_debug = 0]]): mixedParameters
This method has 2 optional parameters.
$result_type
The value of the $result_type parameter to determine the output of the get method.
Fill with string "array" to return the result value with data type array of array.
While the contents of other values to return values with data type array of objects.
$is_debug
The $is_debug parameter is a marker (flag) to enable debug mode.
The value of this parameter can be filled with int 1 to enable debug mode and display the query to be processed.
Fill it with another value to not enable debug mode.
In debug mode, there will be no query execution process to the database system.
Example
Here is the example for get_first in a model class.
class D_Blog_Model extends SENE_Model{
public $table = 'blog';
public $table_alias = 'b';
public function __construct(){
parent::__construct();
}
public function getBySlug($slug){
$this->db->from($this->table,$this->table_alias);
$this->db->where("slug", $this->db->esc($slug));
return $this->db->get_first();
}
...
}SQL Result
The following is the SQL command that generated from D_Blog_Model class methods.
-- result from executing D_Blog_Model::getBySlug('seme-framework-tutorial-1') --
SELECT *
FROM `d_blog` b
WHERE
`slug` = 'seme-framework-tutorial-1'
LIMIT 0, 1;