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

problem with CodeIgniter mail function

$
0
0
I have a problem when using the Mail function from Code Igniter.

When i try to send out an email i get the following error:


Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.


Code:
From: <>
Return-Path: <>
Reply-To: "" <>
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4a5f0f56a2652>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Etc.

Guys please tell me how i send an email from a custom widget?


Model / Entities relation

$
0
0
Hi guys,

on alpha5, I don't think that the entities object is correctly populated.

If my model return an entity or an object and fill the entity.
No fields are casted
No fileds are datamaped
dates aren't muted to TimeObject

Maybe i don't understand something.

2 cases :
I request my model with an object and fill my entity :
$_options in my entity is ignored.

response from my controller :
Code:
{
   "success": true,
   "message": "",
   "data": {
       "firstname": "Darth",
       "lastname": "Vader",
       "username": null,
       "email": "darth@theempire.com",
       "created_at": "2019-02-08 12:27:42",
       "deleted": "0"
   }
}

If i add setter and getter like that in my entity

PHP Code:
public function setCreatedAt(string $dateString)
 
   {
 
       $this->created_at = new Time($dateString'UTC');

 
       return $this;
 
   }

 
   public function getCreatedAt(string $format 'Y-m-d H:i:s')
 
   {
 
       // Convert to CodeIgniter\I18n\Time object
 
       $this->created_at $this->mutateDate($this->created_at);

 
       $timezone $this->timezone ?? app_timezone();

 
       $this->created_at->setTimezone($timezone);

 
       return $this->created_at->format($format);
 
   

my controller return :

Code:
{
   "success": true,
   "message": "",
   "data": {
       "firstname": "Darth",
       "lastname": "Vader",
       "username": null,
       "email": "darth@theempire.com",
       "created_at": {
           "date": "2019-02-08 12:27:42.000000",
           "timezone_type": 3,
           "timezone": "UTC"
       },
       "deleted": "0"
   }
}

OK : created_at is now muted to TimeObject


I request my model with entity in $returnType :

Only fileds are populated setter and getter are not interpreted and $_options is just ignored.

My files :

Models/UserModel.php
PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
UserModel extends Model
{

 
   /**
     * Model Configuration
     */
 
   protected $table      'users';
 
   protected $primaryKey 'id';
 
   protected $returnType '\App\Entities\User';
 
   protected $allowedFields = ['firstname''lastname''username''email''password'];

 
   protected $useSoftDeletes true;
 
   protected $dateFormat 'datetime';
 
   protected $useTimestamps true;

 
   protected $skipValidation     false;
 
   protected $validationRules    = [
 
       'firstname'    => 'required|min_length[3]',
 
       'lastname'     => 'required|min_length[3]',
 
       'username'     => 'required|alpha_numeric_space|min_length[3]',
 
       'email'        => 'required|valid_email|is_unique[users.email,id,{id}]',
 
       'password'     => 'required|min_length[8]',
 
       // 'password_confirm' => 'required_with[password]|matches[password]'
 
       // 'password_confirm' => 'matches[password]'
 
   ];

 
   protected $validationMessages = [
 
       'email'        => [
 
           'is_unique' => 'Sorry. That email has already been taken. Please choose another.'
 
       ]
 
   ];

 
   protected $afterDelete = ['updateDeletedAt'];


 
   /**
     * Protected & internals methods
     */

 
   protected function updateDeletedAt(array $data)
 
   {
 
       if (! isset($data['id']) ) return $data;

 
       $this->builder()
 
           ->whereIn('id'$data['id'])
 
           ->set(['deleted_at' => date('Y-m-d H:i:s')])
 
           ->update();

 
       return $data;
 
   }


Entities/User.php

PHP Code:
<?php namespace App\Entities;

use 
CodeIgniter\Entity;

class 
User extends Entity
{
 
   protected $id;
 
   public $firstname;
 
   public $lastname;
 
   public $username;
 
   public $email;
 
   protected $password;
 
   public $created_at;
 
   protected $updated_at;
 
   public $deleted;
 
   protected $deleted_at;

 
   protected $_options = [
 
       'datamap' => [
 
           'full_name' => 'username'
 
       ],
 
       'dates' => ['created_at''updated_at''deleted_at'],
 
       'casts' => [
 
           'deleted' => 'boolean'
 
       ],
 
   ];

 
   public function setPassword(string $pass)
 
   {
 
       $this->password password_hash($passPASSWORD_BCRYPT);
 
       return $this;
 
   }



Controller/Users.php
PHP Code:
<?php
namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\API\ResponseTrait;

use 
Restserver\Libraries\Format;

use 
App\Models\UserModel;
use 
App\Entities\User;

class 
Users extends Controller
{

 
   /**
     * Entry point for users listing
     */
 
   public function index()
 
   {
 
       $userModel = new UserModel();
 
       $users $userModel->findAll();

 
       $data = [
 
           'success' => true,
 
           'message' => '',
 
           'data' => $users,
 
       ];

 
       return $this->response->setStatusCode(Format::HTTP_OK)->setJSON($data);
 
   }

 
   /**
     * Entry point for specific user
     */
 
   public function show($id)
 
   {
 
       $userModel = new UserModel();
 
       $user $userModel->find($id);
 
       // $user->myDate = $user->created_at->humanize();

 
       if ($user){
 
           $data = [
 
               'success' => true,
 
               'message' => '',
 
               'data' => $user,
 
           ];

 
           return $this->response->setStatusCode(Format::HTTP_OK)->setJSON($data);
 
       }else{
 
           $data = [
 
               'success' => false,
 
               'message' => 'user_not_found',
 
               'data' => []
 
           ];

 
           return $this->response->setStatusCode(Format::HTTP_NOT_FOUND)->setJSON($data);
 
       }

 
   }

 
   /**
     * Entry point for user creation
     */
 
   public function create()
 
   {
 
       $data $this->request->getPost();

 
       // var_dump($data);die;

 
       $userModel = new UserModel();
 
       $userEntity = new User();

 
       if ($userEntity->fill($data)){
 
           if ($userModel->save($userEntity) !== false){

 
               $data = [
 
                   'success' => true,
 
                   'message' => 'resources_created',
 
                   'data' => [],
 
               ];

 
               return $this->response->setStatusCode(Format::HTTP_CREATED)->setJSON($data);
 
           }else{
 
               $data = [
 
                   'success' => false,
 
                   'message' => 'resources_not_created',
 
                   'data' => $userModel->errors(),
 
               ];

 
               return $this->response->setStatusCode(Format::HTTP_NOT_ACCEPTABLE)->setJSON($data);
 
           }
 
       }else{
 
           $data = [
 
               'success' => false,
 
               'message' => 'resource_dont_match',
 
               'data' => [],
 
           ];

 
           return $this->response->setStatusCode(Format::HTTP_BAD_REQUEST)->setJSON($data);
 
       }

 
   }

 
   /**
     * Entry point for user update
     */
 
   public function update($id)
 
   {
 
       $data $this->request->getRawInput();

 
       $userModel = new UserModel();
 
       $userEntity = new User();

 
       if ($userEntity->fill($data)){

 
           if ($userModel->save($userEntity) !== false){
 
               $data = [
 
                   'success' => true,
 
                   'message' => 'resources_updated',
 
                   'data' => ['id' => $id],
 
               ];

 
               return $this->response->setStatusCode(Format::HTTP_OK)->setJSON($data);
 
           }else{
 
               $data = [
 
                   'success' => false,
 
                   'message' => 'resource_not_updated',
 
                   'data' => $userModel->errors(),
 
               ];

 
               return $this->response->setStatusCode(Format::HTTP_NOT_ACCEPTABLE)->setJSON($data);
 
           }
 
       }else{
 
           $data = [
 
               'success' => false,
 
               'message' => 'resource_dont_match',
 
               'data' => [],
 
           ];

 
           return $this->response->setStatusCode(Format::HTTP_BAD_REQUEST)->setJSON($data);
 
       }
 
   }

 
   /**
     * Entry point for user delete
     */
 
   public function delete($id)
 
   {
 
       $userModel = new UserModel();

 
       if ($userModel->delete($id) !== false){
 
           $data = [
 
               'success' => true,
 
               'message' => 'resources_deleted',
 
               'data' => ['id' => $id],
 
           ];

 
           return $this->response->setStatusCode(Format::HTTP_OK)->setJSON($data);
 
       }else{
 
           $data = [
 
               'success' => false,
 
               'message' => 'resource_not_deleted',
 
               'data' => [],
 
           ];

 
           return $this->response->setStatusCode(Format::HTTP_NOT_ACCEPTABLE)->setJSON($data);
 
       }
 
   }


 
   //--------------------------------------------------------------------
 
   // End of file Users.php
 
   //--------------------------------------------------------------------

Accessing Laravel auth library from with CI3

$
0
0
Hi there,

We need to provide single sign on across two systems, one in Laravel 5 and one in CI3. We need to use the Laravel 5 apps auth library (Spatie Laravel Permission https://www.github.com/spatie/laravel-permission) as the authentication library and be able to check the user permissions from within our CI3 application as well. 

I think this should be possible if we use DB sessions in the Laravel app and then include the Laravel auth library via composer in our CI app? I have not used Laravel much myself, so I was hoping someone might have had some experience accessing Laravel functions within CI3, and could point me in the right direction of how to get started? 


Many thanks

Is there some guidance on stepping through CI-enabled code?

$
0
0
Hi,

Along with tutorials and hands-on practice, I'm trying to trace through some of the practice modules I'm using with CodeIgniter.

The problem, as with many libraries, is that it's easy to dig down too deeply.  I'd like to see the flow of e.g. url routing, by watching it happen in my sample code.

Are there any tutorials that run through a debugging session, showing how everything is expanded and translated?



Regards,

Setting $cookieSecure = true;

$
0
0
When I set $cookieSecure = true; in Config/App.php and submit a form I get the following error:

BASEPATH/Security/Security.php at line 193
PHP Code:
186         }
187 
188         
// Do the tokens exist in both the _POST and _COOKIE arrays?
189         if ( ! isset($_POST[$this->CSRFTokenName], $_COOKIE[$this->CSRFCookieName])
190              || $_POST[$this->CSRFTokenName] !== $_COOKIE[$this->CSRFCookieName]
191         // Do the tokens match?
192         {
193             throw new \LogicException('The action you requested is not allowed'403);
194         }
195 
196         
// We kill this since we're done and we don't want to pollute the _POST array
197         unset($_POST[$this->CSRFTokenName]);
198 
199         
// Regenerate on every submission?
200         if ($this->CSRFRegenerate

How do I use this correctly?

How to use a datepicker filter in codeIgniter ?

$
0
0

.png   pic.png (Size: 140.02 KB / Downloads: 2) I want to make a date filter only by year for my event page so people can filter by year so they can see what events are happening by year, but many people are using between date filter which is hard for me to understand, is there anyone can help me build a datepicker filter by year  Huh 

this is my controller : 

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Exhibitions extends CI_Controller {
   
   function __construct() {
       parent::__construct();

       $this->load->helper('general_helper');
       $this->load->helper('date');
       //load pagination library
       $this->load->library('pagination');
       //load post model
       $this->load->model('exhibitions_model');
       //per page limit
       $this->perPage = 10;
   }
   
   public function index(){
       $data = array();
       
       //get rows count
       $conditions['returnType'] = 'count';
       $totalRec = $this->exhibitions_model->getRows($conditions);
       
       //pagination config
       $config['base_url'] = 'http://localhost/demo1/index.php/exhibitions/index';
       $config['uri_segment'] = 3;
       $config['total_rows']  = $totalRec;
       $config['per_page']    = $this->perPage;
       
       //styling
       $config['num_tag_open'] = '<li class="page-item">';
       $config['num_tag_close'] = '</li>';
       $config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="javascript:void(0);">';
       $config['cur_tag_close'] = '</a></li>';
       $config['next_link'] = 'Next';
       $config['prev_link'] = 'Prev';
       $config['next_tag_open'] = '<li class="page-item">';
       $config['next_tag_close'] = '</li>';
       $config['prev_tag_open'] = '<li class="pg-prev">';
       $config['prev_tag_close'] = '</li>';
       $config['first_tag_open'] = '<li>';
       $config['first_tag_close'] = '</li>';
       $config['last_tag_open'] = '<li>';
       $config['last_tag_close'] = '</li>';
       
       //initialize pagination library
       $this->pagination->initialize($config);
       
       //define offset
       $page = $this->uri->segment(3);
       $offset = !$page?0:$page;
       
       //get rows
       $conditions['returnType'] = '';
       $conditions['start'] = $offset;
       $conditions['limit'] = $this->perPage;
       $data['omg_event'] = $this->exhibitions_model->getRows($conditions);
       
       //load the list page view
       
      $this->load->view('templates/header', $data);
     $this->load->view('pages/exhibitions', $data);
      $this->load->view('templates/footer');
   }
   
}


this is my model : 
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Exhibitions_model extends CI_Model{
   /*
    * Get posts
    */
   function getRows($params = array()){
       $this->db->select('*');
       $this->db->from('omg_event');
       $this->db->order_by("date_start", "desc");

       if(array_key_exists("event_id",$params)){
           $this->db->where('event_id',$params['event_id']);
           $query = $this->db->get();
           $result = $query->row_array();
       }else{
           //set start and limit
           if(array_key_exists("start",$params) && array_key_exists("limit",$params)){
               $this->db->limit($params['limit'],$params['start']);
           }elseif(!array_key_exists("start",$params) && array_key_exists("limit",$params)){
               $this->db->limit($params['limit']);
           }
           
           if(array_key_exists("returnType",$params) && $params['returnType'] == 'count'){
               $result = $this->db->count_all_results();
           }else{
               $query = $this->db->get();
               $result = ($query->num_rows() > 0)?$query->result_array():FALSE;
           }
       }

       //return fetched data
       return $result;
   }
}
?>

this is my view : 

Code:
<head>
   <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">  
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>  
   <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>

 <!-- jQuery -->
 <script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <!-- DataTables -->
 <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>

</head>


<!--===============================
=            Hero Area            =
================================-->

<section class="hero-area bg-1 text-center overly">
 <!-- Container Start -->
 <div class="container">
   <div class="row">
     <div class="col-md-12">
       <!-- Header Contetnt -->
       <div class="content-block">

       <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
       <div class="carousel-inner">
         <div class="carousel-item active">
           <img src="<?php echo base_url() ?>img/ads/ad1.jpg" class="d-block w-100" alt="...">
           <div class="carousel-caption d-none d-md-block">
             <br><br><br><br><br><br>
          <h2>Welcome to Industrial Guide Asia</h2>
           <p>As the annual industrial directory, we provides you up-to-date information from the manufacturing, engineering and trading companies classifying advertisements and listing Products & Services, Brand Titles and Trade Shows. Click the button bellow to see around the website !</p>
         </div>
         </div>

         <div class="carousel-item">
           <img src="<?php echo base_url() ?>img/ads/ad2.jpg" class="d-block w-100" alt="...">
           <div class="carousel-caption d-none d-md-block">
             <br><br><br><br><br><br>
           <h2>Our Website Is upgrading</h2>
           <p>Please bare with us if you encounter some problems when you are visiting our websites. We are fixing our website to give you a good website that will be more corporate and user friendly.  </p>
         </div>  
         </div>

         <div class="carousel-item">
           <img src="<?php echo base_url() ?>img/ads/ad3.gif" class="d-block w-100" alt="...">
           <div class="carousel-caption d-none d-md-block">
             <br><br><br><br><br><br>
             <h2>Don't miss every Event this Year</h2>
             <p>Visit the Event page to check what Event that will be held this Year</p>
           </div>
         </div>
       </div>

       <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
         <span class="carousel-control-prev-icon" aria-hidden="true"></span>
         <span class="sr-only">Previous</span>
       </a>
       <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
         <span class="carousel-control-next-icon" aria-hidden="true"></span>
         <span class="sr-only">Next</span>
       </a>
     </div>
         
       </div>
     
       
     </div>
   </div>
 </div>
 <!-- Container End -->
</section>

    <!--==========================
     Services Section
   ============================-->
       <section class="blog single-blog section">
   <section id="services">
     <div class="container">
         <div class="section-title">
         <h2>EXHIBITIONS ROADSHOWS & SEMINAR</h2>
         <p></p>
       </div>      

<table class="table table-hover">
 <div class="category-search-filter">
         <div class="row">
           <div class="col-md-3">
           Filter
             <div class="widget search p-0">
           <div class="input-group">
              <input type="text" name="order_end_date" value="" class="date-own form-control" id="order-end-date" placeholder="Search">
                <button name="filter_order_filter" type="button" class="btn" id="filter-order-filter" value="filter"><i class="fa fa-search fa-fw"></i></button>
               
             </div>
         </div>


 <script type="text/javascript">
     $('.date-own').datepicker({
        minViewMode: 2,
        format: 'yyyy'
      });
 </script>
           </div>
         </div>
       </div>
<?php if(!empty($omg_event)): foreach($omg_event as $post): ?>
 <thead>
   <tr>
   

   </tr>
 </thead>
 <tbody>
 

   <tr>
     <th scope="row"> <?php if(!empty($post['thumb_img'])){ ?>
       <img src="<?php echo base_url().image('upload/'.$post['thumb_img'],120,53); ?>" alt="">
      <?php } ?></th>
     <td width="15%"><?php echo  dateFormat($post['date_start'], 'd/m/Y').' - '.dateFormat($post['date_end'], 'd/m/Y');?></td>
     <td><?php echo $post['name'];?></td>
     <td><?php echo $post['address'];?></td>
     <td width="15%""><a href="">Send Enquiry</a></td>
   </tr>
 <?php endforeach; else: ?>
               <tr><td colspan="3">Post(s) not found......</td></tr>
               <?php endif; ?>
 </tbody>
</table>

    <!-- Pagination -->
       <nav aria-label="Page navigation example">
         <ul class="pagination">
           <?php echo $this->pagination->create_links(); ?>
         </ul>
       </nav>
     
     </div>    

     

     </div>
   </section><!-- #services -->
 </section>

controller of _remap seem to fail.

$
0
0
I build a controller: care.php in App\Controllers\wheels,
for simple testing _remap, the code is as follows.

Assuming the URL is 127.0.0.1/myproject/wheels/care/a1, it will get a1 string.
But,assuming the URL is 127.0.0.1/myproject/wheels/care/bb123, the result will appear "Method App\Controllers\wheels\Care::bb123() does not exis",
it is not as directed to the contentProcess function as I expected,
Please give me help.

PHP Code:
namespace App\Controllers\wheels;
 
use 
CodeIgniter\Controller;
 
class 
Care extends Controller {
 
 
   public function _remap($method, ...$params) {
 
       if (method_exists($this$method)) {
 
           return $this->$method(); // go to a1
 
       }else{
 
            return $this->contentProcess();//go to contrntProcess
 
       }
 
   }
 
 
   protected function contentProcess() {
 
       echo 'contentProcess';
 
   }
 
 
   protected function a1() {
 
       echo "a1";
 
   }
 

Database error in localhost

$
0
0
i downloaded the website from server to localhost and getting the following error

PHP Code:
A Database Error Occurred
Unable to connect to your database server using the provided settings
.

Filenamecontrollers/Home.php

Line Number
24 


This is whats contained in the Home.php file

PHP Code:
    *         http://example.com/index.php/welcome
     
*    - or -
     *         
http://example.com/index.php/welcome/index
     
*    - or -
     * 
Since this controller is set as the default controller in
     
config/routes.phpit's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */


        public function __construct(){
                parent::__construct();
                 $this->load->helper('
form');
                 $this->load->library('
user_agent');
                 $this->load->library('
paypal_lib');
                 $this->load->model('
Ad_model', 'Ad_user');
                 $this->load->model('
User_model', 'user_model');
              $this->load->library('
VRClient');
                 $this->load->library('
form_validation');
           } 



How do i resolve this?

Validation callback function in Model with several parameters

$
0
0
Dear all,

I am trying to use a custom validation callback function, from a model (not from the controller, as I am trying to keep them slim), and this function takes two parameters.

As described in the documentation, I am using arrays to make these methods callable.

Here is a sample of my controller's method :


PHP Code:
public function saveOrUpdate()
{
   $this->load->model('TravelModel');
   if ($this->TravelModel->runValidation() == FALSE) {
       //An error occured --> REPOST form
       //...
   } else {
        //Validation OK --> SAVE values
        //...
   }



Here is a sample of the model's method :

PHP Code:
public function runValidation():bool{
 
  $this->load->library('form_validation');
 
  $this->form_validation->set_rules('title''Title''trim|required|max_length[150]');
 
  $this->form_validation->set_rules(
 
      'startdate',
 
      'Start',
 
      array(
 
          'required',
 
          array($this->TravelModel'endAfterStart['.$this->input->post('enddate').']'),
 
          array($this->TravelModel'isValidDate'),
 
      )
 
  );
 
  $this->form_validation->set_rules('enddate''End', array('required',array($this->TravelModel'isValidDate')));

 
  return($this->form_validation->run());



And finally, an example of two callback functions :

PHP Code:
public function isValidDate(string $date): bool
{
 
  if (isValidBelgianDate($date)) return true;
 
  $this->form_validation->set_message('isValidDate''Date is invalid');
 
  return false;
}

public function 
endAfterStart($startDate$endDate): bool
{
 
  $startDate DateTime::createFromFormat('!d/m/Y'$startDate);
 
  $endDate DateTime::createFromFormat('!d/m/Y'$endDate);

 
  $this->form_validation->set_message('endAfterStart''Start date should be less than end date.');
 
  return ($endDate >= $startDate);



For your info, isValidDate is working perfectly, since this function takes only one parameter.
However endAfterStart is not working. I always get these errors :

Severity: Notice
Message: Array to string conversion
Filename: libraries/Form_validation.php
Line Number: 771


Message: preg_match() expects parameter 2 to be string, array given
Filename: libraries/Form_validation.php
Line Number: 695



What can I do?

If I extend the CI_Form_validation in a MY_Form_Validation, this mechanism is working quite well (you just have to pass multiple parameters as a single string with separators) but I really would like to keep these callbacks in my models together.

Thank you very much.

PHPExcel Export Problem

$
0
0
Please help me, 

This site can’t be reached
The webpage at http://localhost/xxx/xxx/x might be temporarily down or it may have moved permanently to a new web address.
ERR_INVALID_RESPONSE

This is my controller

Code:
function exportData()
    {
        $id = $this->uri->segment(3);
                include APPPATH.'third_party/PHPExcel/PHPExcel.php';
        $excel = new PHPExcel();
        $excel->getProperties()
        ->setCreator('Admin')
        ->setLastModifiedBy('Admin')
        ->setTitle("result")
        ->setSubject("Admin")
        ->setDescription("Admin")
        ->setKeywords("Data Result");
                $excel->setActiveSheetIndex(0)->setCellValue('A1', "Data");
        $excel->getActiveSheet()->getStyle('A1')->applyFromArray($style_col);


        $excel->setActiveSheetIndex(0)->setCellValue('A2', $id);
        $excel->getActiveSheet()->getStyle('A2')->applyFromArray($style_row);
        $excel->getActiveSheet()->getColumnDimension('A')->setWidth(10);

        $excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);
            $excel->getActiveSheet(0)->setTitle("Data Result");
        $excel->setActiveSheetIndex(0);


        $filename='result_detail_'.$id.'.xlsx';
                header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=0');

        $write = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
        $write->save('php://output');
}
Mac OSX, PHP 7.2.15, i was try in PHP 7.3 and not working. 
im using plugin PHPExcel

OKR tool made from CodeIgniter?

$
0
0
Hi,

I want to create our own OKR tool for our department. I have no idea how and where to start. I studied how OKR works, use some existing OKR tools (weekdone.com) and analyze the functionalities. I even created a flowchart for this project.

Also, I tried creating a database design but I'm worried that it won't work.

Can you give me some advice on how to start this OKR project? Can someone help me, please? I highly appreciate that.

Thank you.

Output encryption library

$
0
0
Hi

I use below code for encryption in my app

$this->load->library('encryption');
$this->encryption->initialize(array('cipher' => 'aes-256','mode' => 'cbc','key' => 'abcdefgh01234567abcdefgh01234567'));
echo 
$this->encryption->encrypt('omid'); 


What is encrypt result type?(base64 or hex or other)

Because when i try to decrypt it in android or ios,have an error

How to access the config file of parent controller from sub controller

$
0
0
Hi Team,

Can someone guide me to access the configuration file of parent controller from the sub controllers? 

also how to use the DB configuration file from parent for the sub controllers? so that i need to maintain only one config file. 

Thanks in advance.

Issue with sessions on v3.1.10 and PHP 7.2

$
0
0
I've migrated a bunch of projects to a new server and i'm running into issues with sessions not functioning properly. The same projects on the old server work just fine.

Projects are all using CI v3.1.10 and are using database sessions

The old server the projects were running on was using
  • Apache
  • PHP 5.5.9
  • Ubuntu Server 16.04
The new server is running
  • Apache
  • PHP 7.2
  • Ubuntu Server 18.04
If it makes any difference the new server is a container running on proxmox.5.3

I can see every time i reload the page on one of these projects that new sessions are being created in the database for each page load. When i output the cookies using console.log(document.cookie) i cannot see the session cookie being set which is what i assume is causing a new session to be created on every page load.

I have also tried both http and https to see if theres any difference and the results are the same using either. There's also no information in error logs relating to the sessions either.

Edit config file from browser

$
0
0
I want to create an administration page to edit a configuration file.
Everything must be done by browsers, views etc.
Ideas ???

How to stream response output?

$
0
0
Hi,

is there any possibility to stream response output?

I would like to stream a video to the browser. But because the video's size is to large I cannot do something like

PHP Code:
$response->setBody($video); 
Currently I am using the following construct that I would like to replace:

PHP Code:
while (...)
{
 
 $data fread($handle,$bytesToRead);
  echo 
$data;
  
flush();
  
$bytesToRead = ...;

Could add the https routes ?

$
0
0
Allows developers to establish custom HTTPs routes.

Developers also have the choice to build a specific URL for every HTTPS route.

Thank you.

Autoload function

$
0
0
Hello, I have some doubts about autoload in CodeIgniter.
My first question is that currently, I use __autoload, it has been discontinued? Is not it good practice to use it?
I read about the spl_autoload_register, is it better to use it instead of __autoload?
Also, my other doubt is related to server demand when using autoload, does it load EVERYTHING as soon as the server is loaded or is it on demand?
Because if it loads everything, it would not be good to put many includes there, right?

Thanks a lot ! Blush

The session class has a push method but no pop method

$
0
0
It would be nice to have an inverse method to session::push, for example session::pop.

Captcha image src issue

$
0
0
Hi I am trying to use CI's captcha . All though my captcha is getting created , the src of the captcha img that CI is generating is not correct .

I have an User controller with register function like below : (Complete Controller is at pastebin https://pastebin.com/pSskpuy0)



PHP Code:
public function register(){ 
$this->form_validation->set_rules('user_name' 'Username' 'trim|required|max_length[32]'); 
$this->form_validation->set_rules('captcha' 'Captcha' 'trim|required|max_length[32]|callback_check_captcha');
$this->form_validation->set_rules('password''Password','trim|required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('confirm_password''Confirm Password','trim|required|min_length[5]|max_length[12]|matches[password]');
$this->form_validation->set_rules('email''Email''trim|required|valid_email');
if (
$this->form_validation->run()==FALSE){
//Captcha code 
$this->load->helper('captcha');
//Captcha Config 
$vals = array(
'img_path' => './captcha/',
'img_url' => './captcha/',
'img_width' => '150',
'img_height' => 30,
'expiration' => 7200,
'word_length' => 8,
'font_size' => 16,
'img_id' => 'Imageid',
'font_path' => '/fonts/Open.ttf',

// White background and border, black text and red grid
'colors' => array(
'background' => array(255255255),
'border' => array(255255255),
'text' => array(000),
'grid' => array(2554040)
)
);
//Create the Captcha
$cap create_captcha($vals);

// Store The Created Captcha in DB for Verification 
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$this->register_model->store_captcha($data);
//Load View
$data['image']=$cap['image'];
var_dump($data['image']);exit();
$this->load->view('templates/header');
$this->load->view('register' $data);
$this->load->view('templates/footer');
}else {
$option=array('cost'=>12);
$encrypt_password=password_hash($this->input->post('password'),PASSWORD_BCRYPT,$option);
$this->register_model->add_user($encrypt_password);
$this->session->set_flashdata('user_registered','You are Successfully Registered and can Log in ');
redirect('register/success');
}


If you see the above code I am setting the 'img_path' to './captcha/'(using the root relative method) . I have this folder captcha in the root .

I my view I have :


PHP Code:
<div class="form-group">
 
   <label>Enter UserID</label>
 
   <input type="text" class="form-control" name="user_name"  placeholder="Enter Your UserId">
 
 </div>
 
 <div class="form-group">
 
   <label>Enter Your Email</label>
 
   <input type="email" class="form-control" name="email"  placeholder="Enter Your Email">
 
 </div>
 
 <div class="form-group">
 
   <label>Enter Your Password </label>
 
   <input type="password" class="form-control" name="password"  placeholder="Enter Password">
 
 </div>
 
 <div class="form-group">
 
       <label>Re-enter Password </label>
 
       <input type="password" class="form-control" name="confirm_password"  placeholder="Renter Password">
 
 </div>
 
 <?php echo $image ?>
  <div class="form-group">
        <label>Solve Captcha </label>
        <input type="text" class="form-control" name="captcha" >
  </div>
   <button type="submit" class="btn btn-primary">Submit</button>
  <?php echo form_close();?>

The problem is my image is not showing up . When inspected the captcha image I found it to be correct like below :

Code:
<img id="Imageid" src="./captcha/1551023447.5228.jpg" style="width: 150; height: 30; border: 0;" alt=" ">

However , the src is actually getting 'computed' to : /login/user/captcha/1551023447.5228.jpg]http://[::1]/login/user/captcha/1551023447.5228.jpg  instead of  /login/captcha/1551023447.5228.jpg]http://[::1]/login/user/captcha/1551023447.5228.jpg . 

[Image: FV0ce.png]

Could somebody tell me why the src is pointing to /login/user/captcha/1551023447.5228.jpg]http://[::1]/login/user/captcha/1551023447.5228.jpg all though it should be /login/captcha/1551023447.5228.jpg]http://[::1]/login/captcha/1551023447.5228.jpg and how we can fix this ? Surprisingly the same code is running all right in another project with same directory structure .
Viewing all 14343 articles
Browse latest View live


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