Wednesday, April 20, 2016
Sunday, April 17, 2016
FAQ
If you have problem with base_url(), try this in application>config>config.php:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/codi/";
name of model class and model file name must be same[exactly same]
Ref: user_guide: user_guide/general/models.html?highlight=model
Executing raw SQL:
public function deactivate($id){
$sql='update quotes set active=0 where aid='.$id;
$this->db->query($sql);
}
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/codi/";
name of model class and model file name must be same[exactly same]
Ref: user_guide: user_guide/general/models.html?highlight=model
Executing raw SQL:
public function deactivate($id){
$sql='update quotes set active=0 where aid='.$id;
$this->db->query($sql);
}
Thursday, April 14, 2016
Automatic Table Printer
All you need to do is copy the following code to your view file and call the view from controller and pass the table data as todos. i.e. $data['todos']=$query->result. $this->load->view('view',$data).
<?php
echo "<table>";
//print table headers
if($todos){
echo "<thead>";
foreach($todos[0] as $key=>$val){
echo "<td> $key </td>";
}
echo "</thead>";
//print data
foreach($todos as $todo){
echo "<tr>";
foreach($todo as $key => $val){
echo "<td> $val </td>";
}
echo "<tr>";
}
}else{
echo "<h1>Sorry, No Todo is available</h1>";
}
?>
</table>
Friday, April 8, 2016
Form Validation
Controller
=======
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Config extends CI_Controller {
public function index()
{
if($this->input->post('submit')){
$this->form_validation->set_rules('emp_type','Employee Type','trim|required|min_length[9]');
if($this->form_validation->run()==FALSE)
{
$data=array(
'errors'=> validation_errors()
);
$this->session->set_flashdata($data);
}
redirect('config');
} else{
$this->load->view('config_view');
}
}
}
View
====
<?php echo form_open('config/index');
if($this->session->flashdata('errors')){
echo $this->session->flashdata('errors');
}
echo form_label('Employee Type','emp_type');
echo form_input(array('name' => 'emp_type',
'class' => 'form-control',
'placeholder'=>'Employee Type'
));
echo form_submit('submit','Save',array('class' => 'form-control'));
echo form_close();
?>
=======
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Config extends CI_Controller {
public function index()
{
if($this->input->post('submit')){
$this->form_validation->set_rules('emp_type','Employee Type','trim|required|min_length[9]');
if($this->form_validation->run()==FALSE)
{
$data=array(
'errors'=> validation_errors()
);
$this->session->set_flashdata($data);
}
redirect('config');
} else{
$this->load->view('config_view');
}
}
}
View
====
<?php echo form_open('config/index');
if($this->session->flashdata('errors')){
echo $this->session->flashdata('errors');
}
echo form_label('Employee Type','emp_type');
echo form_input(array('name' => 'emp_type',
'class' => 'form-control',
'placeholder'=>'Employee Type'
));
echo form_submit('submit','Save',array('class' => 'form-control'));
echo form_close();
?>
Thursday, April 7, 2016
Create a Simple API
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class api extends CI_Controller {
public function index($secretkey)
{
//api url http://dilir.me/codi/api/index/916
if(isset($secretkey) && $secretkey==='916'){
$data= json_encode(array(
"status" => true,
"name" => "Dilir",
"mail" => "dilir.khan@example.com",
"quote" =>"Try Simple Solution First"
));
}else{
$data=json_encode(array(
"status" => false
));
}
header('Content-Type: application/json');
echo $data;
}
}
defined('BASEPATH') OR exit('No direct script access allowed');
class api extends CI_Controller {
public function index($secretkey)
{
//api url http://dilir.me/codi/api/index/916
if(isset($secretkey) && $secretkey==='916'){
$data= json_encode(array(
"status" => true,
"name" => "Dilir",
"mail" => "dilir.khan@example.com",
"quote" =>"Try Simple Solution First"
));
}else{
$data=json_encode(array(
"status" => false
));
}
header('Content-Type: application/json');
echo $data;
}
}
Creating a API Example
public function api(){
$app = array();
$app['status']=false;
//url: dilir.me/api.php?auth=abraCadabra
//Check API key for security
if(isset($_GET['auth']) && $_GET['auth']==='abraCadabra'){
$app['status']=true;
$app['name']="Dilir";
$app['mail']="dilir.khan@example.com";
$app['quote']="Try Simple Solution First";
}else{
unset($app);
$app['status']=false;
}
header('Content-Type: application/json');
echo json_encode($app);
}
$app = array();
$app['status']=false;
//url: dilir.me/api.php?auth=abraCadabra
//Check API key for security
if(isset($_GET['auth']) && $_GET['auth']==='abraCadabra'){
$app['status']=true;
$app['name']="Dilir";
$app['mail']="dilir.khan@example.com";
$app['quote']="Try Simple Solution First";
}else{
unset($app);
$app['status']=false;
}
header('Content-Type: application/json');
echo json_encode($app);
}
Subscribe to:
Posts (Atom)