Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14348 articles
Browse latest View live

date time format:2019-04-12T06:51:09.626Z

$
0
0
hello,
I need to convert unix time to 2019-04-12T06:51:09.626Z  this format.
Can anybody help me with this, please.

Also, if possible can you explain this format, is it a some kind of time representation standard.

how to solve [this site can t be reached the connection] this error?

$
0
0
In my application some times this type of error occur. 
This error from network or the application side. how to find out?

Using Typecast in Query Builder or Query

$
0
0
Hello all, I'm having a problem when trying to typecast a value in my Postgres's DB wich is type TEXT to INT to perfom a Order By in a query.
When trying to use the standart QUERY() function I receive errors if I try using "ORDER BY option::int"


PHP Code:
$query_options $this->query("SELECT * FROM integrador_ura_options WHERE fk_ura_id = ? ORDER BY option::int"$fk_ura_id); 

<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: &quot;Type is not supported&quot;. in /var/www/html/integrador/system/Format/Exceptions/FormatException.php:9

And i didn't find any documentation about how to do it using QueryBuilder class.

need to communicate with Extension

$
0
0
I have a Chrome Extension that is installed in the same browser that is hosting my CI based app. I need to communicate from the web app to the Extension. I was told that I could do this by running this in the web app:


Code:
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
 function(response) {
   if (!response.success)
     handleError(url);
 });
This will generate a message that my Extension can see and react to.

The question is "how do I run the above code from my CI based php app"? Is that javascript that I can run when my app starts up? Since the server is generating HTML pages, how do I get this working? I do need to see the result of this call since I will "grey out" certain functions in my web app if the Extension is not found. 

Any clues? 

Error: Unable to load the requested class

$
0
0
Greetings,
I'm doing a web page project that is about printing shipping labels using PHP and easypost API. However I'm having trouble trying to load the library in the controller.

The client php library is on a folder called vendor and it looks like this
vendor/
composer
easypost/easypost-php/lib

Inside the lib folder it looks like this
EasyPost (folder)
cacert.pem
easypost.php

I moved the content inside the lib folder to the application library folder

So after that I tried to load the library in my Shipping.php controller
This is my construct inside shipping controller
PHP Code:
public function __construct() {
parent::__construct();
$this->load->helper('url''form');
$this->load->library('form_validation');

$this->load->library('EasyPost/easypost');



However i get an error
Unable to load the requested class: EasyPost

This is the EasyPost.php code
PHP Code:
<?php

namespace EasyPost;

abstract class 
EasyPost
{
 
   /**
     * @var string
     */
 
   public static $apiKey;

 
   /**
     * @var string
     */
 
   public static $apiBase 'https://api.easypost.com/v2';

 
   /**
     * @var string
     */
 
   public static $apiVersion "2";

 
   /**
     * Time in milliseconds to wait for a connection
     *
     * Zero or null means no timeout.
     *
     * @var int|null
     */
 
   public static $connectTimeout;

 
   /**
     * Time in milliseconds to wait for a response
     *
     * Zero or null means no timeout.
     *
     * @var int|null
     */
 
   public static $responseTimeout;

 
   /**
     * @var string
     */
 
   const VERSION '3.4.1';

 
   /**
     * get the API key
     *
     * @return string
     */
 
   public static function getApiKey()
 
   {
 
       return self::$apiKey;
 
   }

 
   /**
     * set the API key
     *
     * @param string $apiKey
     */
 
   public static function setApiKey($apiKey)
 
   {
 
       self::$apiKey $apiKey;
 
   }

 
   /**
     * get the API base URL
     *
     * @return string
     */
 
   public static function getApiBase()
 
   {
 
       return self::$apiBase;
 
   }

 
   /**
     * set the API base URL
     *
     * @param string $apiBase
     */
 
   public static function setApiBase($apiBase)
 
   {
 
       self::$apiBase $apiBase;
 
   }

 
   /**
     * get the API version
     *
     * @return string
     */
 
   public static function getApiVersion()
 
   {
 
       return self::$apiVersion;
 
   }

 
   /**
     * set the API version
     *
     * @param $apiVersion
     */
 
   public static function setApiVersion($apiVersion)
 
   {
 
       self::$apiVersion $apiVersion;
 
   }

 
   /**
     * Set time in milliseconds to wait for a connection
     *
     * Zero or null means no timeout.
     *
     * @return int|null
     */
 
   public static function getConnectTimeout()
 
   {
 
       return self::$connectTimeout;
 
   }

 
   /**
     * Get time in milliseconds to wait for a connection
     *
     * Zero or null means no timeout.
     *
     * @param int|null $connectTimeout
     */
 
   public static function setConnectTimeout($connectTimeout)
 
   {
 
       self::$connectTimeout $connectTimeout;
 
   }

 
   /**
     * Get time in milliseconds to wait for a response
     *
     * Zero or null means no timeout.
     *
     * @return int|null
     */
 
   public static function getResponseTimeout()
 
   {
 
       return self::$responseTimeout;
 
   }

 
   /**
     * Get time in milliseconds to wait for a response
     *
     * Zero or null means no timeout.
     *
     * @param int|null $responseTimeout
     */
 
   public static function setResponseTimeout($responseTimeout)
 
   {
 
       self::$responseTimeout $responseTimeout;
 
   }




the easypost.php that's not inside the EasyPost folder has this code
PHP Code:
<?php

// Require this file if you're not using composer's vendor/autoload

// Required PHP extensions
if (!function_exists('curl_init')) {
  throw new Exception('EasyPost needs the CURL PHP extension.');
}
if (!
function_exists('json_decode')) {
  throw new Exception('EasyPost needs the JSON PHP extension.');
}

// Config and Utilities
require(dirname(__FILE__) . '/EasyPost/EasyPost.php');
require(
dirname(__FILE__) . '/EasyPost/Util.php');
require(
dirname(__FILE__) . '/EasyPost/Error.php');

// Guts
require(dirname(__FILE__) . '/EasyPost/EasyPostObject.php');
require(
dirname(__FILE__) . '/EasyPost/EasypostResource.php');
require(
dirname(__FILE__) . '/EasyPost/Requestor.php');

// API Resources
require(dirname(__FILE__) . '/EasyPost/Address.php');
require(
dirname(__FILE__) . '/EasyPost/Batch.php');
require(
dirname(__FILE__) . '/EasyPost/CarrierAccount.php');
require(
dirname(__FILE__) . '/EasyPost/Container.php');
require(
dirname(__FILE__) . '/EasyPost/CustomsInfo.php');
require(
dirname(__FILE__) . '/EasyPost/CustomsItem.php');
require(
dirname(__FILE__) . '/EasyPost/Event.php');
require(
dirname(__FILE__) . '/EasyPost/Fee.php');
require(
dirname(__FILE__) . '/EasyPost/Item.php');
require(
dirname(__FILE__) . '/EasyPost/Order.php');
require(
dirname(__FILE__) . '/EasyPost/Parcel.php');
require(
dirname(__FILE__) . '/EasyPost/Pickup.php');
require(
dirname(__FILE__) . '/EasyPost/PostageLabel.php');
require(
dirname(__FILE__) . '/EasyPost/Rate.php');
require(
dirname(__FILE__) . '/EasyPost/Refund.php');
require(
dirname(__FILE__) . '/EasyPost/ScanForm.php');
require(
dirname(__FILE__) . '/EasyPost/Shipment.php');
require(
dirname(__FILE__) . '/EasyPost/Tracker.php');
require(
dirname(__FILE__) . '/EasyPost/User.php');
require(
dirname(__FILE__) . '/EasyPost/Insurance.php');
require(
dirname(__FILE__) . '/EasyPost/Report.php');
require(
dirname(__FILE__) . '/EasyPost/Webhook.php'); 
if i use require_once("application/vendor/easypost/easypost-php/lib/easypost.php");
then everything works fine. But to complete the project I'm required to load the library using codeigniter. 

So what am I doing wrong?

urgent need for codeigniter developer

$
0
0
friends! help to solve the problem with the site poputki.net NOT FREE! the service worked with google maps api and used the api to select settlements and build maps. we want to completely remove the api and map. settlements will need to choose from its own database . please contact me via skype: d.smotrov to discuss the cost and other details.

beta 2 - base_url() inconsistent in namespaces

$
0
0
Greetings.  Is this a bug or am I missing something basic?

base_url() is correct when referenced in the app namespace, but is incorrect in other namespaces (i.e. modules).  
site_url() is correct in both namespaces.

Here is a minimal example of the code I used to create, use, and route modules and the "quirk".

PHP Code:
SETUP:
App/Config/App.php:
       public 
$baseURL 'http://localhost/ci4/';  
       
// the paths.php file has all the directories changed to the real directories on the C: drive
       // The public/index.php was modified to point to the actual config/paths.php file 
       // and index.php was then copied to the localhost directory.  That is the only file on localhost/ci4.

App/Config/Autoload.php:
$psr4 = [
'    Config'       => APPPATH 'Config',
    
APP_NAMESPACE => APPPATH               // For custom namespace
    
'Auth'          => ROOTPATH 'Auth',      // For the module
    
'App'         => APPPATH               // To ensure filters, etc still found,
];

App/Config/Routes.php:
$routes->add'login' 'Auth\Controllers\Login::index');
$routes->add'logout''Auth\Controllers\Login::logout');
$routes->add'/'     'App\Controllers\Home::index');


APPLICATION:

App/Controllers/Home.php:
// site_url() and base_url() both = "http://localhost/ci4/" here
// Make sure user is logged in first: 
$sec = new \Auth\Models\Secmgmt(); 
$security $sec->sec_check();
// if not...
if (!$security['logged_in']) $this->response->redirect(base_url('login'));


Auth/Controllers/Login.php:
// Login form is processed and all is good.  Return to Home now.
// if ($data['logged_in'])  $this->response->redirect(base_url("/"));  ===> goes to 'http://localhost/' and not routed
   
if ($data['logged_in'])  $this->response->redirect(site_url("/"));  ===> goes to 'http://localhost/ci4/'  Yay

Any ideas why the redirect to base_url() fails here?  Same result as $this->response->redirect('/').

Also, it seems that the response class is not available from any models code.  Is that by design, can I redirect in the model code, or did I goof up there too?


Cheers.

CORS Usage in Controller

$
0
0
Hi,

I was working on security of API. Did anyone let me know how we can apply CORS in elegant way?

Or what you recommend for Security of API to not expose to outer world?

Upgrade 2.0.2 to 3.1.10 session problem on local mamp

$
0
0
I'm updating my Codeigniter. I've deleted de system folder and replaced it with the new one. I've followed the Upgrading from 2.2.x to 3.0.x instructions. These are my new settings for the session:

I use autoload for the Session.

$config['sess_driver'] = 'files';

$config['sess_cookie_name'] = 'ci_session';

$config['sess_expiration'] = 0;

$config['sess_save_path'] = APPPATH.'/sessions';

$config['sess_match_ip'] = FALSE;

$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;

I use: 
      $newdata = array(

        'username'  => $member->email,

        'owner_id'  => $member->member_id,

        'logged_in' => TRUE

      );


      $CI->session->set_userdata($newdata);

 can print username, owner_id after the set_userdata, but when I redirect to the default page in my admin, I get $_SESSION empty

(except for the __ci_last_regenerate )

The folder is "OK"(I can see the new session).
I'm using MAMP PRO 5.3 with on port 8890 for ssl. I've tried database driver with same results.

I've tried PHP 7.1.26, 7.0.33, 5.6, 7.3.3

Thanks

Using method save when table has composite index

$
0
0
I have a problem, when inserting data into a table with a composite index
Can anyone help me ?
In betha-1 version, I use replace method, and run succesfully. But in version betha 2  I got error 
"Return value of CodeIgniter\\Model::replace() must be of the type bool, object returned"

convert value from routes/uri to string

$
0
0
Controller
PHP Code:
public function verification($activation$email)
{
    
$user $this->model->user('user_activation'$activation);


Model
PHP Code:
public function user($key$value)
{
 
   return $this->db->query("
       SELECT *
         FROM users
         WHERE 
$key = $value // The problem here
     "
)->row();



The error message is directed to $ value, the value of $ activation is taken from routes / url.
I try to use single quotes so that it becomes '$ value'. and the results are correct.
my question is whether using single quotes doesn't matter? or is there a better way?

Please Help me to Set & Display Property Value From Library Between Two Pages

$
0
0
Hello, i am first to try create own library and i get some problem to display values from property between to pages.
.
[The Problem]
1. Imagine I have a simple library that functions only for set and get property.
2. This library will later be called in the controller.
3. In this controller consists of two pages page, the first is main page (index() function) and display page (display() function)
4. Now this problem starts here, I will load the library that I explained in point 1 in the initController() function. in the index() function I give the task to set the property value in my library and then I will redirect it to the display page (display() function). On display page (display() function) I want to display the value that I have set on the index () page. is this possible?
.
for the details look the picture below ^_^

[MyLibrary + Services]
[Image: Iovs5Tf3RvyjVBk32DQ_ZQ.png]

[Controller]
[Image: kkBDFwpdRL6s8u9BOe4O9A.png]

It's possible to set and display property value on separate function? Thanks ^_^

Freelancer at 10$/H

$
0
0
Hello EveryOne,

I am steve. I am having 7+ years experience on php, code-igniter, laravel,yii, node, angular, and mobile technology. If you are looking for an developer kindly contact me on eia.steveaustin@gmail.com

Thanks
Steve A.

problems in insert checkbox value and corresponding text value.

$
0
0
I want to insert multiple checkbox value and corresponding textbox value in to database. some times its working well most of the time the textbox value inserted as 0
i try lot of method . 
input form
Code:
checkbox
<input type = "checkbox" id="mycheck1" name="certid[]">
<input type = "checkbox" id="mycheck2" name="certid[]">
<input type = "checkbox" id="mycheck3" name="certid[]">
<input type = "checkbox" id="mycheck4" name="certid[]">
<input type = "checkbox" id="mycheck5" name="certid[]">

textitem
<input type="text"  name="noc1[]" id="eprimaryincome1" size="2" value="850"  >
<input type="text"  name="noc1[]" id="eprimaryincome2" size="2" value="300"  >
<input type="text"  name="noc1[]" id="eprimaryincome3" size="2" value="300"  >
<input type="text"  name="noc1[]" id="eprimaryincome4" size="2" value="300"  >
<input type="text"  name="noc1[]" id="eprimaryincome5" size="2" value="300"  >
method 1
Code:
$date = new DateTime("now");
 $today = $date->format('Y-m-d');
   $Specilized_category = $this->input->post('certid');
   $amt = $this->input->post('txt');
   $data=array('appno' =>$appno,'regno' =>$regno ,
   'certid'=>json_encode(implode(",", $Specilized_category)),
    'noc' => 1 ,
    'date' => $today ,
    'amt' => $amt
);
$this->db->insert('appdet', $data);

method 2
Code:
$certid = $this->input->post('certid');
 $count = count($certid);
 $amt = $this->input->post('txt',TRUE);
 $date = new DateTime("now");
 $today = $date->format('Y-m-d');
 $noc=1;
 $data =array();
 for($i=0; $i<$count; $i++) {
 $data[$i] = array(
          'appno' => $appno,
          'regno' => $regno,
          'certid' => $certid[$i],
          'noc' => $noc,
          'date'=> $today,
          'amt'=>$amt[$i]

          );
method 3
Code:
if(isset($_POST['certid']) && $_POST['certid']!="")
{
 

 $certids = $this->input->post('certid');  //here you leave the [ ] out!
 $nocs = $this->input->post('noc1');
 //print_r($nocs);
 $amtt = $this->input->post('txt');  

  $field1_array = isset($_POST['certid']) ? $_POST['certid'] : array();
   $field2_array = isset($_POST['noc1']) ? $_POST['noc1'] : array();
   $field3_array = isset($_POST['txt']) ? $_POST['txt'] : array();

   $total_rows = count($field1_array);

   if ($total_rows > 0)
   {
       for ($i=0; $i<$total_rows; $i++)
       {
       $field1_val = $field1_array[$i];
       $field2_val = $field2_array[$i];
       $field3_val = $field3_array[$i];

       $date = new DateTime("now");
 $today = $date->format('Y-m-d');

        $insert = array();
       $insert[] = array(
         'appno' => $appno,
         'regno' => $regno,
          'certid' => $field1_val,
             'noc' => 1,
             'date' => $today,
             'amt' => $field3_val
               );      
     
       $this->load->model('user_Model');
       $this->User_Model->studreginsert($insert);            
       }
   }
method 4
Code:
$certids = $this->input->post('certid');  //here you leave the [ ] out!
$nocs = $this->input->post('noc');
$nocs = isset($_POST['noc'][$i]) ? 1 : 0;
$result = array();

foreach ($certids as $index=>$certid) {
  $result[] = $certid . '_' . $nocs[$index];
}

$date = new DateTime("now");
    $today = $date->format('Y-m-d');

foreach($result as $value)
       {
       list($certid,$noc) = explode ('_',$value);
        $insert = array();
       $insert[] = array(
           'appno' => $appno,
           'regno' => $regno,
          'certid' => $certid,
             'noc' => $noc,
             'date' => $today
               );      
all methods working well but some times. that amt inserted as '0'. 
Code:
$value = $this->input->post('formvalue', TRUE);
this can also be not worked. Kindly help me to solve my problem .

.jpg   app_error.jpg (Size: 60.15 KB / Downloads: 3)

Codeigniter Query Builder - finding the number of records from a certain date not wor

$
0
0
Within codeigntier, I have the following:

Code:
echo $this->db->where('FROM_UNIXTIME(`last_login`) >=','NOW() - INTERVAL 1 DAY')->from('users')->count_all_results();

The above produces the result: 0

I used print_r($this->db->last_query()); to get the actual sql string being run and it is as follows:

Code:
SELECT COUNT( * ) AS  `numrows`
     FROM  `users`
    WHERE FROM_UNIXTIME(  `last_login` ) >= NOW( ) - INTERVAL 1
    DAY

When I run it from with mysql, I get the correct result: 1.

I am guessing that the escaping is now working or something but cannot figure it out. Any idea?

why Codeigniter database query is case-insensitive?

$
0
0
Hi guys,

I want database query to be case sensitive. I have set the table Collation to be "utf8_bin", which is supposed to be case sensitive. However, when I ran the following query code:
$this->db->where('code', $code);
$this->db->select('*');
$query=$this->db->get('my_table');
return $query->row();

I found that the query was not case-sensitive. For example, my_table has a row where code="abc" but no row with code="Abc". However, if I use $code="Abc" and do the query,  which is expected to return null, but it actually returns the row where code="abc".

So, any ideas how I can make the query case-sensitive? BTW, I am using Codeignitr 3.X

Thank you!

Tranform mysql sql into codeigniter query

$
0
0
Hello,

I have this mysql select:

Code:
SELECT id, zile, status, nr_inmatriculare,title,start_date,end_date,doc_type, contact_emails
           FROM (SELECT datediff(cd.end_date,curdate())  as zile, c.id,
                      c.nr_inmatriculare, c.status,cd.title,cd.end_date,cd.start_date, cd.doc_type, c.contact_emails
                         FROM car_docs cd
                         INNER JOIN cars c ON c.id = cd.car_id
                         WHERE c.status > 0

                       ) as s WHERE zile > -2190 AND title LIKE 'ITP' ORDER BY zile ASC
 
And I'm trying to tranform it into codeigniter query this is what I done:

Code:
return $this->db->select('id, zile, status, nr_inmatriculare,title,start_date,end_date,doc_type, contact_emails')
                   ->where('DATEDIFF(cd.end_date, current_date) as zile, c.id, c.nr_inmatriculare, c.status, cd.title, cd.end_date, cd.start_date, cd.doc_type, c.contact_emails')
                   ->from('car_docs cd')
                   ->join('cars c','c.id = cd.car_id','inner')
                   ->where('c.user_id',$this->session->userdata['user_id'])
                   ->where('c.status >',0)
                   ->where('zile >' ,-2190)
                   ->like('title', 'ITP')
                   ->order_by('zile', 'ASC')
                   ->get()->result();

But is not working. What I need to change?

Two functions, one shared view and plenty of fields. Trying to DRY my code

$
0
0
Here's my idea: let's say my form has 20 fields.
I have two methods: add, update.
Defining each field inside mentioned functions will take too long time.
I'm looking for the way to define my fields once and put them inside each of those functions.
How to do it? Is there simpler way?
Should I create the function for defining my fields in controller and a function to list my fields in view? Huh
 
Please, have a look at my code:

My controller:
PHP Code:
function add() {
        if ( 
$this->form_validation->run() ) {    //validation success: add data and redirect
            
$data = array(
                
'title' => $this->input->post'title' ),
                
'content' => $this->input->post'content' ),
            );
            
$jammy_id $this->Jammy_model->add_jammy$data );
            
redirect'jammy2/index' );
        }     
//validation not successfull
        
else { //params for the view and input data from user
            
$params'_view' ] = 'jammy/edit';
            
$params'action' ] = 'jammy2/add';
            
$params'title' ] = $this->input->post'title' );    
            
$params'content' ] = $this->input->post'content' );
            
$this->load->view'layouts/main'$params );
        }
    }
    
//________________________________________________________________________________________
    
function update$id NULL ) {
        if ( 
$this->Jammy_model->get_jammy$id ) ) {    //check if jammy exists in db table
            
$data'jammy' ] = $this->Jammy_model->get_jammy$id );
        } else {    
//jammy ain't exist, show 404
            
show_404();
        }
        if ( 
$this->form_validation->run() ) { ////validation success: set and add data, redirect
            
$data = array(
                
'title' => $this->input->post'title' ),
                
'content' => $this->input->post'content' ),
            );
            
$jammy_id $this->Jammy_model->update_jammy$id$data );
            
redirect'jammy2/index' );
        } else { 
//params for the view and input data from user
            
$params'_view' ] = 'jammy/edit';
            
$params'action' ] = 'jammy2/update/' $id;
            
$params'title' ] = $data'jammy' ][ 'title' ]; //dane z bazy
            
$params'content' ] = $data'jammy' ][ 'content' ]; //dane z bazy
            
$this->load->view'layouts/main'$params );
        }
    } 

My view contains only field variables like $title, $content etc.
My model contains only simple functions for db operations.

Login/Register/User page setup, connection reccomendations

$
0
0
Hello all!

Ive researched all around but still feel I need help Ive attached a screenshot of my landing page. I would like to connect a login/register page to the button shown which afterwards would lead to a main page or user account. Like a social network. How do I connect the login.php/register.php and its controllers to this button? I have to create an html to connect with both and link that to the button? Are there any templates that folks could send my way to check out? Thank you! (I used the welcome_message.php for my landing page)


Heart Heart ,
Mekaboo

.png   Screenshot_2019-04-13 CULTURED KINK.png (Size: 17.92 KB / Downloads: 7)

coneccting database sql to codeigniter manually.

$
0
0
[Image: open?id=15pB90hOfr-S-GQVMEll4dTFQMhV5ego5][Image: open?id=1Bk-fTfy8iQsRAFxbQfNxxLXRNIvP7bwW]hi, im doing a database with codeigniter to my school, and i have finish my database but i dont know how that it works, i try to put my database in C:\xampp\htdocs\crud\application\config\database.php but doesnt work.

thanks you.
Viewing all 14348 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>