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

PHP Notice: Undefined variable: _SERVER

$
0
0
i was using nginx server and i  changed to apache 2.4. 
iam using ci 3.1.8 version
php version is 7.1.18
i guess server connection lost but why i have no idea why 

[Mon Mar 04 13:13:04.598041 2019] [php7:notice] [pid 4992:tid 1108] [client 51.11.0.4:56252] PHP Notice:  Undefined variable: _SERVER in C:\\Interface\\html\\application\\config\\config.php on line 28, referer: http://51.11.0.21/

PHP Code:
Line 27$root=(isset($_SERVER['HTTPS']) ? "https://" "http://").$_SERVER['HTTP_HOST'];
Line 28$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), ''$_SERVER['SCRIPT_NAME']);

Line 30$config['base_url'] = $root

Webhooks not working

$
0
0
I have a website that allows me to setup a Webhook to post data from their site to my own. I have this working on one of my other sites that uses a standard PHP script. When I try to get it to work with a codeigniter site, the page doesn't even get called. Any ideas why it would be different? Only think I can think is whether codeigniter is blocking another domain from posting data to it?

Tilde(~) in Path Breaks CI4 (used in iCloud Drive Path)

$
0
0
CI4 breaks when it encounters a path that has a tilde(~) in it.
Unfortunately, Apple uses tildes in its iCloud Drive path name, which is rendered as:
Code:
/Users/username/Library/Mobile Documents/com~apple~CloudDocs


When using PHP's built-in web server on MacOS:
Code:
cd  /Users/moo/Library/Mobile Documents/com~apple~CloudDocs/Sites/ci4b1/
php -S localhost:8892 -t $(pwd)/public
... the user-visible path
Code:
/Users/myname/Sites/ci4b1/
...ACTUALLY resolves to
Code:
/Users/myname/Library/Mobile Documents/com~apple~CloudDocs/Sites/ci4b1/
Returning this response:
Code:
Fatal error: Uncaught Error: Class 'Config\App' not found in /Users/myname/Library/Mobile Documents/com~apple~CloudDocs/Sites/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php on line 139

The same fatal error returns when executing spark at the CLI if the CI4 folder is located in a path containing a tilde(~) .

Code:
➜  ci4b1 pwd
/Users/moo/Desktop/folder_with_a_tilde~/ci4b1
➜  ci4b1 ./spark
PHP Fatal error:  Uncaught Error: Class 'Config\App' not found in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php:139
Stack trace:
#0 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php(80): CodeIgniter\Config\Config::createClass('Config\\App')
#1 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Common.php(99): CodeIgniter\Config\Config::get('Config\\App', true)
#2 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/bootstrap.php(158): config('Config\\App')
#3 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/spark(44): require('/Users/moo/Desk...')
#4 {main}
 thrown in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php on line 139

Fatal error: Uncaught Error: Class 'Config\App' not found in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php:139
Stack trace:
#0 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php(80): CodeIgniter\Config\Config::createClass('Config\\App')
#1 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Common.php(99): CodeIgniter\Config\Config::get('Config\\App', true)
#2 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/bootstrap.php(158): config('Config\\App')
#3 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/spark(44): require('/Users/moo/Desk...')
#4 {main}
 thrown in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php on line 139
➜  ci4b1

How to check if a user logged in?

$
0
0
I can check and restrict access to certain methods or controllers by defining a helper method
PHP Code:
function checkLoggedIn() {
 
   if (session('loggedin') == true) {
 
       return true;
 
   }
 
   header("Location: /login");
 
   exit;


Then an example usage is as below.

PHP Code:
namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Home extends Controller
{
 public function 
index()
 {
 return 
view('welcome_message');
 }

 
   public function showme($page 'home')
 
   {
 
       checkLoggedIn();
 
   }
}

class 
AdminHome extends Controller
{
 
   public function __construct()
 
   {
 
       checkLoggedIn();
 
   }

 
   public function index()
 {
 return 
view('welcome_message');
 }


Do you have any better method than this helper method? E.g. in laravel there are guards. Could I achieve something similar without having to write too much of code?

Model->chunk() with Entities

$
0
0
I was surprised to see that chunk (https://codeigniter4.github.io/CodeIgnit...ts-of-data) was returning on object of type stdClass instead of my model-defined return type (which happens to be an entity). A simple way to replicate:
PHP Code:
$myModel = new MyModel();

foreach (
$myModel->findAll(20) as $row)
    
var_dump($row);
        
$myModel->chunk(2, function ($row)
{
    
var_dump($row);
}); 

First two objects from var_dump are App\Entities\MyEntity whereas the two from chunk() are stdClass.

I traced the difference back to system/Model.php where findAll (line ~362) passes a parameter to getResult while chunk (line ~992) doesn't.
I'm glad to open a pull request but I'm not sure if this is actually the intended/desired behavior? There's no documentation on chunk except for the user guide I linked above.

Temporary DB prefix override

$
0
0
Is there a way to override the database prefix for a specific query or duration? or a toggle on-off? Scenario is dozens of tables all prefixed and one library-specific table that isn't, so now all my models are built around the non-prefixed name and I want to write a single CLI Command to access the "external" table but don't seem to be able to do it...

Looking for junior developer, a native English speaker

$
0
0
Hello,

I am developing a free content management system on CodeIgniter4. Already there is the first version with which you can make a simple site with the admin.

http://basic-app.com/page/download

Requires a junior programmer, for whom English is a native language, to check articles and documentation for literacy.

My web development experience is about 10 years, I think that cooperation can be mutually beneficial on partnership grounds, but I am ready to consider the option of checking texts for a fee. Be sure to need a programmer to correctly translate all technical terms.

CI 4 Marketing

$
0
0
Hey all!

I was just wondering on a more high level what plans are being made to market Codeigniter 4. As it stands now, most people, communities, and companies see CI as legacy software. If CI wants to be seen as a decent choice next to other frameworks that are popular right now, there will need to be some marketing efforts to try to change peoples perceptions.

Has any thought been put into this?

view with namespace not work

$
0
0
Hello,

I am trying to create a view using a namespace but it does not perform giving me error. What happens is that it will not fetch the path from the namespace but rather the path of the Config /../ Views / namespace folder.

Can anyone help me.

Thanks

Can we setup HMVC without the Modular Extensions?

$
0
0
Is there a way to setup/use HMVC or something similiar without the Modular Extensions? Maybe cascading from MY_Controller?

Thanks

Failed to decode session object. Session has been destroyed

$
0
0
I am sometime experiencing the following issue :

Quote:ERROR - 2019-03-05 19:57:26 --> Severity: Warning --> session_start(): Failed to decode session object. Session has been destroyed /system/libraries/Session/Session.php 143

Impossible to replicate the issue since I got this thrown in my server log. Any ideas what could be the roots of that problem and/or where to start ?

Setting up FPDI_Protection in CI 4 [namespace giving me a challenge]

$
0
0
I am trying to generate a pdf( using FPDI_Protection) in CI 4 but i keep getting this error 

"Class 'FPDF' not found
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}"



Quote:In my client controller i have

Code:
namespace App\Controllers;
use CodeIgniter\Controller;

use App\Libraries\pdf\fpdf;
use App\Libraries\pdf\fpdi;
use App\Libraries\pdf\FPDI_Protection;

class Client extends Controller{
protected $pdf;
function __construct(){
    helper('url');
   $this->pdf = new FPDI_Protection();
}
public function download_invoice($client_code){
   
    $this->pdf->SetProtection(array('print'),'12345','');
    $this->pdf->AddPage();
    $this->pdf->SetFont('Arial');
    $this->pdf->Write(10,'blah blah blah blah blah blah blah.');
    $this->pdf->Output('D', 'test_invoice.pdf', true);
  }

}
   







Quote:FPDI_Protection.php  file link here
PHP Code:
namespace App\Libraries\pdf//I included this namespace 
use App\Libraries\pdf\fpdf// but this class cannot be found
use App\Libraries\pdf\fpdi;
/*****************************************************************************
 * Software: FPDI_Protection                                                 *
 * Version:  1.0.6                                                           *
 * Date:     2016/01/04                                                      *
 * Author:   Klemen VODOPIVEC, Jan Slabon                                    *
 * License:  Freeware                                                        *
 *                                                                           *
 * You may use and modify this software as you wish as stated in original    *
 * FPDF package.                                                             *
 *                                                                           *
 * Infos (by Jan Slabon):                                                    *
 * This class extends the FPDI-class available at https://www.setasign.com   *
 * so that you can import pages and create new protected pdf files.          *
 *                                                                           *
 ****************************************************************************/

class FPDI_Protection extends FPDI
{
 
 //Never mind the code inside i excluded it for this thread





Quote:fpdi.php file 
PHP Code:
<?php
namespace App\Libraries\pdf//I included this namespace
/**
 * This file is part of FPDI
 *
 * @package   FPDI
 * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
 * @license   http://opensource.org/licenses/mit-license The MIT License
 * @version   1.6.2
 */

if (!class_exists('FPDF_TPL')) {
    require_once('fpdf_tpl.php');
}

/**
 * Class FPDI
 */
class FPDI extends FPDF_TPL
{
 
//Never mind the code inside i excluded it for this thread

Quote:fpdf.php file
PHP Code:
<?php
namespace App\Libraries\pdf;
/*******************************************************************************
* FPDF                                                                         *
*                                                                              *
* Version: 1.81                                                                *
* Date:    2015-12-20                                                          *
* Author:  Olivier PLATHEY                                                     *
*******************************************************************************/

define('FPDF_VERSION','1.81');

class 
FPDF
{
////Never mind the code inside i excluded it for this thread


Error when generating the pdf file is as follows:

"Class 'FPDF' not found
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}"

Multiple domains with one codebase - how to set htaccess file?

$
0
0
Hi,

I have multiple domains (two at the moment, but might be more later on), and I want them all to use the same CodeIgniter codebase, but each domain will use its own database.

I have the basic concept figured out (I hope), but the only thing I'm struggling with is the htaccess file. I want it to handle the removal of index.php from the url, as well as redirect to https and www.

Below is my .htaccess file.
On localhost it works well, but on the remote servers it creates an seemingly endless chain of index.php/index.php/index.php etc.

What am I missing here?

If it matters, I'm using CI 3.1.9



Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#localhost
RewriteCond %{HTTP_HOST} localhost
RewriteRule ^(.*)$ http://localhost/pi/index.php/$1 [NC,R,L]

#firstdomain
RewriteCond %{HTTP_HOST} firstdomain.com
RewriteRule ^(.*)$ https://www.firstdomain.com/index.php/$1 [NC,R,L]

#seconddomain
RewriteCond %{HTTP_HOST} seconddomain.com
RewriteRule ^(.*)$ https://www.seconddomain.com/index.php/$1 [NC,R,L]

Why is Code Igniter not recommended?

$
0
0
I have been checking out Code Igniter recently and it seems incredibly easy to get an idea going very quickly with little work.
I have primarily been learning Symfony and haven't looked at Code Igniter mainly because there seemed to be a mass consensus that something like Laravel/Symfony etc would be better but I decided to checkout it again and was pleased with the experience. Its simplicity is a real plus point for me.
What are the reasons that Code Igniter might not be recommended?

Overriding Session Expiration?

$
0
0
So I'm working with a site that has "unlimited" (very long expiration time) sessions so that a user doesn't have to keep logging in all the time, however this isn't really ideal if a user uses an insecure (e.g- shared) system, as they'll stay logged in.

What I'd like to do is add a "Keep me logged in" checkbox on the login page so that I can have default behaviour with a short (or on close) expiration time, and then override that with the much longer expiration time (or the other way around, if easier).


Now I know how I'd do this if I was using PHP's session functions directly, but is there a proper way to do this with CodeIgniter's session class? Also if there is an easier way to do this on CodeIgniter 4 do let me know; I hadn't intended to upgrade just yet (too much other stuff still to get done) but I can move it forward if it will make this easier to implement.

Thanks!

pager->links() not work in view layouts

$
0
0
I am using beta-1 and try to print pagination links using "pager->links()" or "pager->simpleLinks()" but nothing comes out if I do that within "this->section('content')" .

NOTE: Without View layouts works fine.

Same code as the one used in the user guide:
Code:
<!-- LAYOUT -->
<!doctype html>
<html>
<body>
<?= $this->renderSection('content') ?>
</body>
</html>

Code:
<!-- TEMPLATE -->
<?= $this->extend('layout') ?>
<?= $this->section('content') ?>
<?= pager->links() ?>
<?= $this->endSection() ?>

Kind regards and congratulations for this best jobs!

A PHP Error was encountered Severity: Notice Message: Undefined index:

$
0
0
Hi I have a site which was previously built by someone we no longer deal with and whilst I have been able to sort many issues out one keeps getting my all twisted,

I have an area on my dashboard which allows me to add a file to upload a pdf

and when on the front end it gives me a clickable link.

I now need to add an extra PDF in the same format, so I have copied the code in the admin modules added it below the other PDF and changes the details as required  and have been able to make it appear in the dashboard it all works adds the file to the DB and puts it in the correct folder.

then I copied the relevant code for the front end change the details and the link appears but i get this error message.



A PHP Error was encountered
Severity: Notice
Message: Undefined index: acccesories_fitting_pdf_file
Filename: views/index.php
Line Number: 104

the code for this is

Code:
<?php
                }
                
                if(!empty($accessories[0]['accessories_fitting_pdf_file']))
                {
                    ?>
                    <div class="bullet-box-content">
                        <a href="<?php echo base_url(); ?>images/accessories_images/pdf/<?php echo $accessories[0]['acccesories_fitting_pdf_file']; ?>" target="_blank">Fitting Instructions</a>
                    </div>   

Which was a copy of this
<?php
                if(!empty($accessories[0]['accessories_pdf_file']))
                {
                ?>
                    <div class="bullet-box-content">
                        <a href="<?php echo base_url(); ?>images/accessories_images/pdf/<?php echo $accessories[0]['accessories_pdf_file']; ?>" target="_blank">View Drawing</a>
                    </div>


the complete index.php code is as follows

<div class="container-fluid">

<?php
if(!empty($accessories) && !empty($accessories[0]['accessories_banner_image']))
{
?>
    <div class="row">
        <div class="col-sm-12 pl0 pr0">
          <div class="product-banner-bg">
              <img src="<?php echo base_url(); ?>images/accessories_images/<?php echo $accessories[0]['accessories_banner_image']; ?>" alt="" title="" class="img-responsive"/>
            </div>        
        </div>
    </div>
<?php
}
?>

<div class="clearfix"></div>

<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div class="product-hd">Accessories</div>
            <div class="medium-hd"><?php echo $accessories[0]['accessories_name']; ?></div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="content">
                <?php echo html_entity_decode($accessories[0]['accessories_description']);

                /*<!--<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac libero vitae ligula fringilla sollicitudin non in lacus.
                Aliquam non nulla at nisi maximus pharetra id at sapien. Pellentesque ullamcorper imperdiet ex. Praesent eu finibus nisl, id viverra
                 mauris. Sed iaculis erat a dolor mattis eleifend. Integer dolor augue, fermentum sed mauris a, pretium ornare ligula. Fusce ut
                 orci sem. Curabitur sit amet neque sit amet erat scelerisque iaculis. </p>-->*/ ?>
            </div>
        </div>
    </div>
    
    <?php
    if(!empty($accessory_images) && count($accessory_images) > 0)
    {
    ?>
    <div class="row">
        <div class="col-sm-12">
            <div class="medium-hd"></div>
            <div class="content">
                <div id="links-install" class="links">
                    <?php
                    $accessory_img_cnt = 0;
                    
                    foreach($accessory_images as $acc_img)
                    {
                        $accessory_img_cnt = $accessory_img_cnt + 1;
                    ?>
                        <div class="col-sm-3 mt15 mb15 product-border">
                             <a href="<?php echo base_url(); ?>images/accessories_images/<?php echo $acc_img['accessories_image']; ?>" title="Accessory image <?php echo $accessory_img_cnt; ?>">
                            <img src="<?php echo base_url(); ?>images/accessories_images/<?php echo $acc_img['accessories_image']; ?>" alt="Accessory image <?php echo $accessory_img_cnt; ?>" class="img-responsive">
                            </a>
                        </div>
                    <?php
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
    <?php
    }
    ?>
    
    <?php
    if(!empty($accessories[0]['accessories_pdf_file']))
    {
    ?>
    
    <div class="row">
        <div class="col-sm-12">
            <div class="medium-hd"></div>
            <div class="content">
                <?php
                if(!empty($accessories[0]['accessories_pdf_file']))
                {
                ?>
                    <div class="bullet-box-content">
                        <a href="<?php echo base_url(); ?>images/accessories_images/pdf/<?php echo $accessories[0]['accessories_pdf_file']; ?>" target="_blank">View Drawing</a>
                    </div>
                <?php
                }
                
                if(!empty($accessories[0]['accessories_zip_file']))
                {
                    ?>
                    <div class="bullet-box-content">
                        <a href="<?php echo base_url(); ?>images/accessories_images/zip/<?php echo $accessories[0]['accessories_zip_file']; ?>" target="_blank">2D Drawings</a>
                    </div>
                <?php
                }
                
                if(!empty($accessories[0]['accessories_fitting_pdf_file']))
                {
                    ?>
                    <div class="bullet-box-content">
                        <a href="<?php echo base_url(); ?>images/accessories_images/pdf/<?php echo $accessories[0]['acccesories_fitting_pdf_file']; ?>" target="_blank">Fitting Instructions</a>
                    </div>    
                    <?php
                }
                ?>
                
            </div>
        </div>
    </div>
    
    <?php
    }
    ?>

</div>
<script>
    document.getElementById('links-install').onclick = function (event)
    {
        event = event || window.event;
        var target = event.target || event.srcElement,
            link = target.src ? target.parentNode : target,
            options = {index: link, event: event},
            links = this.getElementsByTagName('a');
            blueimp.Gallery(links, options);
    };
</script>


I have looked everywhere for a refernce but I am obviously missing something basic. please could someone help?

CodeIgniter 4.0.0 Development Continues

$
0
0
We have finally reached our first beta release for 4.0.0  Cool 
We have a number of bugs to track down & fix, probably with at least one more beta, before deeming V4 ready to launch, but we are getting closer!

We haven't forgotten about the features that did not make the first release, nor the suggestions raised in the feature requests subforum. I have created a github project board in our repo, to track/visualize major features as they progress from discussion through possible inclusion in an upcoming release. Discussion & feedback for each feature will be on a thread in this subforum.

Be patient while we spin up this next evolutionary stage for CI4.

Is it possible to use nested loops in parser templates?

$
0
0
I am not sure if nested loops are supported by the parser, at least I am not able to display the following template correctly:
Code:
<table class="data_table">
  <thead>
    <tr>
      {header_entries}
        <th>{header_title}</th>
      {/header_entries}
    </tr>
  </thead>
  <tbody>
    {data_entries}
      <tr>
        {data_row}
          <td>{data_cell}</td>
        {/data_row}
      </tr>
    {/data_entries}
  </tbody>
</table>

The headers works but not the table's body when using these data:


Code:
   $header_entries = [['header_title' => 'one'],
                      ['header_title' => 'two']];
   $data_entries = [['data_row' => [['data_cell' => 'one - one'],
                                    ['data_cell' => 'one - two']],
                     'data_row' => [['data_cell' => 'two - one'],
                                    ['data_cell' => 'two - two']]]];
   $parser = \Config\Services::parser();
   echo $parser->setData(['header_entries' => $header_entries,
                          'data_entries' => $data_entries])->render('templates/data_table_template');

[feature] REST support

$
0
0
I am currently teaching a course on enterprisey RESTful backends, and discovering some corrections and opportunities for better REST support in CI4, which I plan to roll in when ready. These are being developed in the feature/resource branch of the CI4 repo.

Planned so far:
[.] better explanation for handling REST requests, splitting the routing explanation into its own page
[x] ResouuceController as a starter for a REST endpoint
[ ] more flexible treatment for API-like routing
[.] clearer split between resource state & resource presentation routing/handling, perhaps with a base controller
[ ] better explanation for returning appropriate responses & data formats
[ ] better explanation & perhaps code improvements to handle incoming data
[ ] tutorial for building a RESTful resource or API service (might end up in user guide, might not)

----------------------------------------------------
This is a roadmap feature, or "epic", and a card on the roadmap board.
Component tasks will show up as issues or PRs on the development board.
We welcome comments & suggestions below.
Viewing all 14343 articles
Browse latest View live


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