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

Need help with language helper

$
0
0
Can you help me ?
I cannot switch my language into my view.

Here is my config.php

$autoload['helper'] = array('url', 'file', 'language');
$autoload['language'] = array('homepage');

My view is on php like that : <?= lang('carousel_title'); ?>

My controller : public function index($language = 'french')

And here is my routes :

// Routes française
$route['fr'] = 'Page/index';

// Route Anglaise
$route['en'] = 'Page/index/english';


My problem, is for every url, i'm in french. /en didn't work. How set the default language for an user in my controller ?

Dynamic subdomain routing with .htaccess in CodeIgniter 3

$
0
0
Is it possible to route subdomains in a CodeIgniter 3 application using only .htaccess?

What I'm trying to achieve, as an example: I have mysite.localhost.com, and then I'll have multiple subdomains like client1.mysite.localhost.com, client2.mysite.localhost.com, and so on.

I need mysite.localhost.com to point to my 'Home' controller, which will be a landing page.

Then, I need all subdomains to point to mysite.localhost.com/client/, passing the subdomain as a parameter to the 'index' function of the 'client' controller.

I've tried all I could think of, without luck. The following works using plain PHP, but not in CodeIgniter (maybe because of routes.php?), it gives a 500 Internal Server Error (I'm guessing a loop, but I can't figure out how to solve it):

Code:
RewriteCond %{HTTP_HOST} !^mysite\.localhost\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-_]+)\.mysite\.localhost\.com$ [NC]
RewriteRule ^(.*)$ client/%1$1 [L]

To be clear, I need URL masking, not redirecting. Following the above examples, this is what I'm trying to achieve:

Code:
client1.mysite.localhost.com --> mysite.localhost.com/client/client1
client2.mysite.localhost.com --> mysite.localhost.com/client/client2
client3.mysite.localhost.com --> mysite.localhost.com/client/client3

And so on...

Thanks in advance!

undefined variable

$
0
0
Hi Friends,

Good day!

I am asking for help.

I just started learning code igniter.

and have some source that I followed.

during the testing.

I encountered undefined variable

on the following.
please see below code


Quote:<?php
defined('BASEPATH') or exit('No Direct Script Access Allowed');



class Users_model extends CI_Model{

   //Declares Private Variable

   private $_userID;
   private $_name;
   private $_userName;
   private $_email;
   private $_password;
   private $_status;
   
   public function setUserID($userID) {
       $this->$_userID = $userID;
   }

   public function setEmail($email) {
       
       $this->$_email = $email;
   }

   public function setPassword($password) {
       $this->$_password = $password;
   }

   public function getUserInfo(){
       $this->db->select(array('u.user_id','u.uname','u.email'));
       $this->db->from('user as u');
       $this->db->where('u.user_id',$this->_userID);
       $query = $this->db->get();
       return $query->row_array();
   }

   function login(){
       $this->db->select('user_id','name','email');
       $this->db->from('user');
       $this->db->where('email', $this->$_email);
       $this->db->where('password', $this->$_password);
       $this->db->limit(1);
       $query = $this -> db ->get();
       if($query ->num_rows() == 1){
           return $query->result();  
           } else {
               return false;
           }

       }    
}


?>


also below is the error


Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _email

Filename: models/Users_model.php

Line Number: 23

Backtrace:

File: D:\xampp\htdocs\webdev\msit\application\models\Users_model.php
Line: 23
Function: _error_handler

File: D:\xampp\htdocs\webdev\msit\application\controllers\Users.php
Line: 65
Function: setEmail

File: D:\xampp\htdocs\webdev\msit\index.php
Line: 315
Function: require_once

I encountered undefined variable on the following

Message: Undefined variable: _email
Message: Undefined variable: _password
Message: Undefined property: Users::$users
and also
Message: Call to a member function login() on null


Thank you in advance

CodeIgniter 4.0.0-beta.2 Released

$
0
0
CodeIgniter-4.0.0-beta.2 launches today [Image: smile.gif]

This is a pre-release of 4.0.0. It is not suitable for production! (but it is pretty darn close)


Highlights:
  • A number of fixes & improvements, importantly for the Model and testing classes
  • Models now require a primary key
  • Generated API docs accessible at https://codeigniter4.github.io/api/
  • Validation rules have been enhanced
  • .htaccess beefed up
New messages:
  • Database.noPrimaryKey, forFindColumnHaveMultipleColumns, Database.forEmptyInputGiven
App changes:
  • updated app/Config/Events
  • added app/Controllers/BaseController
  • added tests/ folder for unit testing
  • added phpunit.xml.dist for unit testing configuration

Check the changelog for details, and the installation writeup for further directions.
Looking to upgrade from CI3 to CI4?

We might need one more  beta round, as we continue to fix remaining bugs and tighten up the code.
Thank you to the community for stepping up to help make this the best PHP framework!

Do NOT post support questions or feature requests in response to this thread - those will be deleted. Instead, use the appropriate CodeIgniter 4 subforum. We are trying to make the best of the limited resources that we have!

Thank you, and ENJOY!

[split] Windows vs Linux split (CodeIgniter 4.0.0-beta.2 Released)

$
0
0
James, I know this is a longshot, but you wouldn't happen to know the split between linux based codeigniter apps and windows based are out there would you?

beta 2: filter files missing in composer install

$
0
0
Hi, I just did a new Composer appstarter install and I moved the directories around for a shared system (as usual).

Just running the canned welcome message and I got
ERROR: codeigniter4\framework\system\Filters\DebugToolbar not found

It seems the files: CSRF.php  DebugToolbar.php  and Honeypot.php are missing from the distribution.

====
Update: It seems the initial composer create-project installed alpha 4, but I swear I remember seeing Beta 2 on the running display.
A 'composer update' just now installed Beta 1. weird. I manually moved the beta 2 files over to work around all this.

I am testing CodeIgniter 4, but I am getting this error:

$
0
0
Fatal error: Default value for parameters with a class type hint can only be NULL in C:\xampp\htdocs\CodeIgniter4-develop\system\Config\DotEnv.php on line 121
What am I missing?

Where is Beta 2 Release

$
0
0
Yesterday we have got beta release from announcement,while checking github page there is no beta 2 release, which is needed for manual installation

New ,htaccess file

$
0
0
I had to add this to the new ,htaccess file to get it to remove index.php from the url
on Windows 10 Pro.

Code:
    # Remove index.php from URL
    RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
    RewriteCond %{THE_REQUEST}                ^[^/]*/index\.php [NC]
    RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

IDEA: Centralized userId

$
0
0
Hi all- I’ve been working on a number of Addins, and I try to keep them “configuration lite”, but a frequent need is to know the current logged in user. See for example my Visits library, which doesn’t no Auth of its own but would like to record any logged in users with the traffic record. Currently I handle this by checking $_SESSION[‘user_id’], and supplying a config file so folks can provide their Kennedy location. But working on anew library with the same issue has me wondering:would it be useful to have CI store the userid after login, accessible as a core service or config?

Error after upgrading from beta1 to beta2

$
0
0
Hello to all.
I am writing a new application on CodeIgniter 4,
everything was OK.
Manually updated from beta1 to beta2.
There was an error:
http://ai.ysu.su/ci4-errors.jpg
Please tell me how to fix the error?
Thank you in advance

PHP 7.3.4 Released

$
0
0
PHP 7.3.4 Has been released this is a Security and Bug fix.

Sub Directory on Controller

$
0
0
Hello,

I decided to try codeigniter version 4 now,
.
But I found a problem when trying to use the subdirectory in my controller.
.
This preview my code.
.


[Structor Subdirectory + Class]
[Image: YMbwJhm.jpg]

[Controller Shoes.php]
[Image: cf4nLPv.jpg]

[Accessing Url]
[Image: 3voDAfg.png]

^_^ please help me to make this work .. thanks brother

search a value in multiple columns

$
0
0
Hi, Sorry if it is very basic question but I have been struggling with it. I am able to find a user by it's id, but I want to search user by id,name,email,salary or address. So when there is input in search form, my code should search that input value in all columns of table and show result if there is any match. Here is my code which works for search with id.

form in view :

<form method="post" action="<?php echo base_url(); ?>users/find">
<input type="text" placeholder="ID" name="id">
            <input type="submit" value="Search">
        </form>



method in controller users:

    public function find() {
        $fd = $this->input->post();
        $this->load->model('HomeModel');
        $data['user'] = $this->HomeModel->test($fd);
        $this->load->view('found', $data);
        
    }


method in model:

    public function test($id) {
        
        $query = $this->db->get_where('users',$id);  
      return $query->row_array();
      
    }


view to display data :

<?php extract($user); ?>

in table .....
                            <td><?php echo $id; ?></td>
                            <td><?php echo $name; ?></td>
                            <td><?php echo $age; ?></td>
                            <td><?php echo $salary; ?> </td>
                            <td><?php echo $address; ?> </td>




Thanks.

Codeigniter Query

$
0
0
i have problem to saving data

this is my Model
i use Sql Server Database

  function UpdateEdit($data)
  {

     $this->db->trans_start();
     $sql = " update [do] set customer='" . $data['Customer'] . "', tgl='" . $data['Tgl'] . "', Notes='" . $data['Notes'] . "', Total=" . $data['Total']
          . " where doid='" . $data['Doid'] . "'";    
     print_r($sql);

      $head =  $this->db->query($sql);

     $this->db->delete("from DoDtl where Doid='" . $Doid . "'");

     $this->db->query($data['Detail']);
     $this->db->trans_complete();

     return TRUE;
  }

Advanced languages

$
0
0
Hi all,
I think that codeigniter should have languages files have 2 dimensional arrays instead of only 1.

For example if i need to have modular setup, each language file could handle all translations in file per module separated in array by keys. This would make language files more flexible, less files to load per translation, less files and changes per project update / commit.

What do you think?

Trouble with the db connection

$
0
0
I'm trying to retrieve stuff from db, but I'm getting this error:


Code:
Call to undefined function CodeIgniter\Database\MySQLi\mysqli_init()



Code:
SYSTEMPATH/Database\MySQLi\Connection.php at line 107

Code:
107         $this->mysqli = mysqli_init();

My db config:

PHP Code:
public $default = [
        
'DSN'      => '',
        
'hostname' => '0.0.0.0',
        
'username' => 'username',
        
'password' => 'p4ssw0rd',
        
'database' => 'db_name',
        
'DBDriver' => 'MySQLi',
        
'DBPrefix' => '',
        
'pConnect' => false,
        
'DBDebug'  => (ENVIRONMENT !== 'production'),
        
'cacheOn'  => false,
        
'cacheDir' => '',
 
               'charset'  => 'utf8mb4',
        
'DBCollat' => 'utf8_general_ci',
        
'swapPre'  => '',
        
'encrypt'  => false,
        
'compress' => false,
        
'strictOn' => false,
        
'failover' => [],
        
'port'     => 3306,
    ]; 

The query I'm running:
PHP Code:
$query $db->query('SELECT * FROM table_name'); 



I have PHP 7.2.4, MySQL 8 in 5 compatibility mode, Windows 10, CI4 beta 1

Comparison Operators >= in Control Structures why false?

$
0
0
What am I doing right?

PHP Code:
$date  '2019-04-07';

$date1 '2019-04-01';
$date2 '2019-04-15';
$date3 '2019-04-16';
$date4 '2019-04-30';

 
       if ($date >= $date1 && $date <= $date2) {
     
       return $this->db->query("
                SELECT *
                FROM incomes
                WHERE income_campaign = '00001'
                AND income_date BETWEEN '
$date3' AND '$date4'
                "
)->result_array();
 
       } else {
     
       return $this->db->query("
                SELECT *
                FROM incomes
                WHERE income_campaign = '00001'
                AND income_date BETWEEN '
$date1' AND '$date2'
                "
)->result_array();
 
       


My question :

PHP Code:
$date  '2019-04-07';

$date1 '2019-04-01';
$date2 '2019-04-15';
$date3 '2019-04-16';
$date4 '2019-04-30';

 
       if ($date >= $date1 && $date <= $date2) { // FALSE VALUE WHICH SHOULD BE TRUE
     
   CODE // CODE ABOVE SHOULD SHOULD EXECUTE THIS CODE
 
       } else {
     
   CODE // BUT THE CODE ABOUT EXECUTING THIS CODE
 
       }

// $date >= $date1 && $date <= $date2
// I think this produces true value but why does it produce false values?
// How to produce true value? 

New session each refresh!!

$
0
0
My codeigniter 3.1.10 keeps giving a new session on each refresh nearly. Cannot figure out why but i'm up to like 1.3 million of them now [Image: biggrin.gif]

PHP Code:
Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'v_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'users_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE

Encrypt sql user and password

$
0
0
Hello,

I’m wondering if there is any way that database username and password inside config/database.php can be encrypted, so developers and others who might have access to the host can’t see those. Any ideas?

Thanks !
Viewing all 14346 articles
Browse latest View live


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