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

Upgrade CI2x to CI3 (USA ONLY)

$
0
0
We are looking for someone that is VERY knowledgeable in CI that will upgrade our existing version from CI2 to CI3 in the next couple of weeks to come.

If you cannot accomplish this task without perfection, please do not commit to doing this.


Please PM me with a quote to what we are asking for along with a time frame to how long it will take you from start to finish.


(USA RESIDENTS ONLY)

set_cookie() doesn't work with redirect()

$
0
0
Hello,
This is my code:

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

class 
Home extends Controller
{
    public function 
__construct()
 
 {
 
   helper(['cookie']);
 
 }
    public function 
page1()
    {
        
set_cookie('test''testvalue-'.time(), time() + 86400);
        return 
redirect()->to('page2');
    }
    public function 
page2()
    {
        echo 
get_cookie('test');
    }


Redirect is working but there is no 'test' cookie on page2. Please help.

Redirect

$
0
0
Hi,
I have created a BaseController extending CI Controller :

Code:
<?php namespace App\Controllers;

class BaseController extends \CodeIgniter\Controller
{

    protected $env_data;
    protected $env_user;
    
    function __construct()
    {
        $this::init();
    }

    function init() {
        $this->env_data = ['init'=>'yes'];
        $this->env_user = [];

        if(empty($this->env_user)) {
            return redirect()->to('/login');
        }
    }


}
I then created controller Home2 :

Code:
<?php namespace App\Controllers;

class Home2 extends BaseController
{

    public function __construct()
    {
        parent::init();
    }

    public function index()
    {
        print_r($this->env_data);
        
        //return redirect()->to('/login');

        return view('welcome_message', $this->env_data);
    }
}
Calling Home2 displays array $this->env_data containing "init"=>'yes'. The redirection does not work.

Can someone confirm this is the expected result?

Why is redirection not working in BaseController?

Thanks in advance!

Session/Redis question

$
0
0
If I'm using redis for sessions and I store some session data in variables for 'user' (active user data) and 'business' (active business) and then I get those session variables with:

$session->get('user');
$session->get('business');

Is that making two calls for the redis server?

Am I better off doing:

$data = $session->get();

$data['user'];
$data['business'];

Is that one call?

I'm running my application on the Google Cloud. I'm obviously trying to reduce calls to the redis server and can't see those calls like database calls in the debug bar. That would be sweet if I could... but not necessary if I knew what is happening.

Bonus question, the session docs mention data will be stored in $_SESSION superglobal. Is that true for redis?

Thanks in advance!

use try catch in index.php file

$
0
0
Hello,

I need to call view if there is any php error in all scripts(controllers, models, libraries...), I thought to use (try catch) in index.php file to call view file in catch block, but I think will be not good from side of performance what do you think, there is other method to handle any error in all script ?

Custom Validation doesn't work?

$
0
0
Hi, I want to create custom validation rule but it not working.

Config/Validation

Code:
    public function test_validate(string $str, string &$error = null): bool
    {
        $error = 'test error';
        return false;
    }

App\Model
Code:
    protected $validationRules = array(
        'name'     => 'required|test_validate'
    );

Result
Quote:CodeIgniter\Validation\Exceptions\ValidationException

{0} is not a valid rule.

For additional question, can someone give simpler example how to send parameters to the function? I don't get the 'require_with' example.
https://codeigniter4.github.io/CodeIgnit...-parameter

The new validation system is hard to understand compared to the previous callback system.

Pagination links

$
0
0
I'm having a little trouble with pagination links, I'm building a jobsite and on the front end when viewing jobs the pagination works fine with no problem.

In admin I have a similar method that lists jobseekers, it is here that I'm having the trouble, the pagination links appear on this page and when I click the links the results appear to be changing correctly, i.e the next set of 12, but the actual pagination link doesn't change.

the url ends with, /admin/jobseekers

when I click the first pagination link the url goes to /admin/jobseekers/12

Then I click the next pagination link and I get /admin/jobseekers/24 and so on as it increments by 12 each time, the results are also correctly serving each set of 12.

So I have discovered that the pagination itself is working but the problem is with the actual pagination links:

So when the page loads the pagination links are like:

<ul class="pagination">
<li class="page-item"></li><li class="page-item active"><span class="page-link">1</span></li>
<li class="page-item"><a href="http://codeigniter.local/admin/jobseekers/12" class="page-link" data-ci-pagination-page="2">2</a></li> 

etc etc

Now the error happens when I click '2'

The link structure isn't changing, number one should become a hyperlink and number two should be just a span, but for some reason it does not change, it's like the links are stuck in the same format with number one being a span and all the others after it are links.

I've been trying to figure this out for days and just cannot get to the bottom of it, I'm sure this must be something simple that I am overlooking but I just cannot pin point where the cause is.

Like I said I have a job list method that works fine and I have tried to mirror the code but still the links will not change, could anybody please advise? Does somebody with more experience recognise this issue and might know what it is?

Where to create model, view, controller folders for my projects

$
0
0
Hi,
I writing PHP code using XAMPP & Code Igniter. I have created for for storing in view & class for controller. Now if my project folder name is abc which is directly under htdocs & also codeigniter (ci3) folder is also under htdocs.

Where I can save above view & class files - in which folder?

Kindly help by correctly suggesting same.


Shreeniwas

PHP 7.3.0 Released

$
0
0
PHP 7.3.0 has now been released.

Creating widgets containing links to pages

$
0
0
I've made an open-source blogging application and I need some help with it. The application supports not only posts, but pages too.

also uploaded an instance of the application, with dummy content, on my server. Click on HERE to see it.

The concrete problem: in the footer of the site I display some pages (not posts). The way I display them is unsatisfactory for me, because it implicates hardcodeing:

   

Code:
<div class="col-sm-6 col-md-3">
      <h3>Legal</h3>
       <ul class="list-unstyled">
       <?php foreach ($pages as $page): ?>
        <li><a href="<?php echo base_url('pages/page/') . $page->id; ?>"><?php echo $page->title; ?></a></li>
       <?php endforeach; ?>
      </ul>
   </div>    


This allows me to display the pages in only one "box". Maybe I would find a solution that lacks... elegance (it would involve some if statements) to display two pages in each box


Perhaps widgets (like WordPress has) would be a good idea. Widgets in which I could drag-and-drop (links to) pages and other entities. I have not found any tutorials on making widgets in Codeigniter.

I don't now if CI has helpers or any other features to support widget creation. I am a beginner (intermediate at best) PHP developer so I don't know where to start creating this feature. Please help. Come with the best approaches.

form_open adds index.php to path

$
0
0
Hi,
Using form_open('your/path') adds the index.php to the absolute path in the final HTML while using base_url('your/path') does not.
Posting form data is not working when I use .htaccess to remove index.php from the path AND index.php is part of the absolute path. 
I suggest removing index.php from all CI generated path in the future so all functions will output a path like base_url for consistency.

If you have the same problem as I had not being able to post form data using form_open() you can use the following code instead:
<form action="<?= base_url('your/path')?>" method="post" accept-charset="utf-8"> 

I use the following code in .htaccess to remove index.php and redirect:

#1) redirect the client from "/index.php/foo/bar" to "/foo/bar"
RewriteCond %{THE_REQUEST} /index\.php/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [NE,L,R]
#2)internally map "/foo/bar" to "/index.php/foo/bar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

email library special charactetr in subject problem

$
0
0
Hi,

While using email library and setting $CI->email->subject() with string that contains a 'š' character, script hangs/stops.

Whithout 'š' character in string everything works as expected.


It this a bug or?

Using CI version 3.1.8

Cheers, Erik

Once the model is loaded by the controller all model methods are exposed to view

$
0
0
If in Controller I do this:

Code:
$this->load->model('mymodel');
//...do some stuff with mymodel...

//calling the view
$vars['somedata'] = 'mydata';
$this->load->view('someview', $vars);


Inside the View someview.php you can do this
Code:
$this->mymodel->someMethod();

Isn't this a security threat? Huh

The View should only be able:
  • to see the data passed by the Controller
  • and to load others Views
but the View should NOT be allowed to call directly methods of any model.

Alpha.4 coming Dec 15th

$
0
0
We are providing a heads up for the next alpha release, planned for Sat Dec 15th.

It will contain a minor backwards compatibility break, in order to align the path constants and folder names used in CodeIgniter 4:

- The *application* folder gets renamed *app* (matching *APPPATH*)
- The *BASEPATH* constant gets renamed *SYSTEMPATH* (matching the *system* folder)
- The remaining folders and constants remain the same
- The source code has been modified to accommodate these

There will be a few changes for you to make when upgrading to this release:
- rename your *application* folder to *app*, if you download the framework or use an app installer
- global replace "application/" with "app/"
- global replace "BASEPATH" with "SYSTEMPATH"
- there may be similar adjustments to other parts of your code, depending on how much you have customized things

Once the dust has settled, paths will be set in a limited number of places:
- spark & system/bootstrap.php;  the path constants are set in these, the two intended entry points.
- app/Config/Paths.php - this class defies properties istead of constants, so that you might apply rules to determine their setting.

Our goals are two fold:
- Have stable & consistent path & folder naming, as we move forward
- Make it easier to handle developer preferences, if they want a different folder structure

The pull request that makes this happen is #1579, in case you wish to test the change yourself.
Please let us know your thoughts & concerns.

is this migration bug?

$
0
0
i just create migration by using CLI command

Code:
php spark migrate:create MoveFrameworkVersion

and look like everything work fine

Code:
C:\Users\pakkapon\Documents\Github\kotatsu-ci4>php spark migrate:create MoveFrameworkVersion

CodeIgniter CLI Tool - Version 4.0.0-alpha.3 - Server-Time: 2018-12-09 03:55:38am

Created file: App/Database/Migrations/20181209035538_MoveFrameworkVersion.php


but when i have to run migration using comamnd

Code:
php spark migrate:version 20181209035538

and error occur

Code:
C:\Users\pakkapon\Documents\Github\kotatsu-ci4>php spark migrate:version 20181209035538

CodeIgniter CLI Tool - Version 4.0.0-alpha.3 - Server-Time: 2018-12-09 03:56:01am

Migrating to version 20181209035538...
An uncaught Exception was encountered

Type:        TypeError
Message:     Argument 1 passed to CodeIgniter\Database\MigrationRunner::version() must be of the type integer, string given, called in C:\Users\pakkapon\Documents\Github\kotatsu-ci4\system\Commands\Database\MigrateVersion.php on line 129
Filename:    C:\Users\pakkapon\Documents\Github\kotatsu-ci4\system\Database\MigrationRunner.php
Line Number: 189

even i don't chance any line of code after create migration file. i still get this error? how can i fixed it?

PS. This is my pc info

 - OS: Windows 10 (1809)
 - Web server: Apache 2.4.34
 - PHP version:  7.1.20

Thank you.

{memory_usage} in Codeigniter 4?

Cart Class Issue

$
0
0
I Am Building an E-commerce Site Using Codeigniter 3. The site was Running fine until i faced a huge bug in the cart class of the system.

The CI Cart or Session Class Does  not Matches user ip address by default and also if there is anything in the session of cart  class from one ip address and if it remains as it is from that ip and someone else from another ip address adds something in the cart session... the old session data from the other ip gets included into the new users data


it seems to be a real issue or m i missing something???  Undecided Undecided

CodeIgniter 4 installation shall not require composer

$
0
0
IMHO one of the main thing that makes CodeIgniter attractive to the developer that approaches for the first time an MVC framework, and what makes it different from big frameworks (like Sinfony and Laravel) is the CodeIgniter extremely simple installation process that do not require to install, learn and use another tool like Composer.

I don't know if you still remember when you installed CodeIgniter for the first time, I was in hurry and I didn't have time to waste playing with another tool (Composer), hence I decided to give CodeIgniter 3 a try because it was the only framework comparable (by widespread user base, and online support/tutorials, etc.) to Laravel/Symfony, but CodeIgniter did not require me to waste time learning another tool.

Hence, I think CodeIgniter 4 installation shall not require Composer to be used at all.

What do you think about this?

Codeigniter framework not loading the page

$
0
0
Our Live webserver is deployed in Redhat Linux OS and got critical issues as we are not able to login into that server as because of root user got corrupted. Hence, we planned to take the backup and deployed in another server with same setup as like live server..But, the application developed using codeignitor framework alone not working properly..Was checked DB connectivity which work perfectly and even other applications which are developed in normal PHP are working fine with any issues including DB connectivity.

Kindly help me on this to fix the issue as it is very very urgent. Screenshot for the same is as attached..

Regards,
K.Prabhakaran

.jpeg   IMG-20181210-WA0028.jpeg (Size: 468.24 KB / Downloads: 2)

Help need for composer package

$
0
0
Hello,

I'm starting a simple composer package for ci4 : https://github.com/bvrignaud/ci4-admin
The goal is to have a simple admin panel.
It's base on Ion-Auth and AdminLTE.

I'm noob with create composer package.

I have some problem with the views.
I'm unable to load views in the Controllers.
I think it's a problem with the namespace declaration in composer.json.

Have you an idea please.

Thanks
Viewing all 14069 articles
Browse latest View live


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