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

How to get values from single coloumn

$
0
0
Hello,


I have a table for personal data, which contains contents such as name, address, gender, etc.
now I want to calculate the total male or female from the gender column, so I make a sql query like this:

Code:
SELECT gender, COUNT(*) AS total
FROM personaldata
GROUP BY gender

the result is :

Quote:man : 3
woman : 6





So, how do I write the code on the model and controller and display it on my website?
this is my code so far:

PHP Code:
   public function total_gender()
 
   {
 
       $this->db->select('gender, count(*) as total');
 
       $this->db->from('personaldata');
 
       $this->db->group_by('gender');

 
       $query $this->db->get()->row()->total;
 
       return $query->result();
 
   


Thank you and sorry for my bad english   Angel

Benchmark codeigniter4

Admin App

$
0
0
Hi there . I'm new to ci enviroment  and i have some questions to some more experienced users .
Is there any chance to have separate admin app folder and logic like wordpress does ? 
Separate routes frontend from backend ?
loading routes per  first uri segment? 

Right now i've installed ci4 and moved index.php and htacces file back into root  folder , added admin foder(custom script not related to ci4) i can acces  backend and everything works fine there (not loading any  ci4 classes ).
yoursite .com /codeiniter/admin/index.php?page=settings&do=permalinks 
front end works fine .. but doesn't seems to be the right way to do it .
working on xampp localhost so /codeigniter folder it's a must,  no virtual host added.
Thanks !

Code:
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # If you installed CodeIgniter in a subfolder, you will need to
    # change the following line to match the subfolder you need.
    # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
    RewriteBase /codeigniter/

    # Redirect Trailing Slashes...
   RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
   # such as an image or css document, if this isn't true it sends the
   # request to the front controller, index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /codeigniter/index.php/$1 [L]

    # Ensure Authorization header is passed along
   RewriteCond %{HTTP:Authorization} .
   RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Naming of Controllers - any names not allowed?

$
0
0
I am building an application, and wanted to have one of the controllers called Resources. No matter what I try, my app will not allow me to use this name - when I try to use a link `<a href="<?php echo base_url(); ?>resources">`, I get an "Object Not Found" error instead of the page. With any of my other controllers, I have no issues. Is Resources a restricted word for controllers?

Routes 4.0.0-beta.2

$
0
0
Hy all .
I have some user defined routes stored in database to do some redirects .
example user/register (database stored) redirect  to register (app defined route )
My thoughts  of the day were to inject into Config\Routes or Events::on('pre_system'
PHP Code:
$routes->setAutoRoute(false);
$routes->add('login''Login::index');
$routes->add('register''Register::index');

 $routes->addRedirect('user/fff''/register'); //ErrorException Undefined offset: 1 SYSTEMPATH/Router\Router.php at line 472
$routes->addRedirect('user/fff''register' );  //ErrorException strpos() expects parameter 1 to be string, array given
$routes->addRedirect('user/fff''Register::index'); // not working SYSTEMPATH/Router\Router.php : 483 
  
throw RedirectException::forUnableToRedirect($val, $this->collection->getRedirectCode($key)); 

but seems that Config\Routes is called twice  and throw error when adding the redirect
How to inject new routes redirection and where ? Before declaring   route ? after ?

.png   Capture.PNG (Size: 38.09 KB / Downloads: 2)

Never ending testing ENVIRONMENT

$
0
0
Can we get rid  of some 'ENVIRONMENT ' things  in the core ? 24  +4 debugger
Production means PRODUCTION  so no more  checking  ENVIRONMENT   inside core
PHP Code:
    if (ENVIRONMENT !== 'testing')
        {
            if (
ob_get_level() > 0)
            {
                
ob_end_flush();
            }
        }
        else
        {
            
// When testing, one is for phpunit, another is for test case.
            
if (ob_get_level() > 2)
            {
                
ob_end_flush();
            }
        } 

quote [b]ciadmin [/b] 'Spark is long dead. Check the date of the tutorials that mention it.' 
https://forum.codeigniter.com/thread-651...#pid331775
no Spark check in production 
PHP Code:
// Never run filters when running through Spark cli
        if (! defined('SPARKED'))
        {
            $possibleRedirect $filters->run($uri'before');
            if ($possibleRedirect instanceof RedirectResponse)
            {
                return $possibleRedirect->send();
            }
            // If a Response instance is returned, the Response will be sent back to the client and script execution will stop
            if ($possibleRedirect instanceof ResponseInterface)
            {
                return $possibleRedirect->send();
            }
        }

// Never run filters when running through Spark cli
        
if (! defined('SPARKED'))
        {
            
$filters->setResponse($this->response);
            
// Run "after" filters
            
$response $filters->run($uri'after');
        }
        else
        {
            
$response $this->response;
        } 
no benckmark in Production
PHP Code:
    //    $this->benchmark->stop('controller_constructor');
        //    $this->benchmark->stop('controller'); 

is_cli() is needed by my website ? NO  but 17 is_cli() switch is performed
checks
PHP Code:
if (is_cli() && ! (ENVIRONMENT === 'testing'))
        {
            return 
md5($this->request->getPath());
        } 
So production = bool(false) ;

PHP sessions expire after X minutes

$
0
0
Hello,

Since few days, I have a problem with my sessions with codeigniter.
They expire after approximately 16/17 minutes. Nothing change in my code and everything was working good before.

Sessions are generated like this :

PHP Code:
$this->session->set_userdata('user'$username); 

My autoload.php :

PHP Code:
$autoload['libraries'] = array('database''session'); 

My config.php :

PHP Code:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE

My phpinfo (PHP Version 7.2.17) :

[Image: screen.png]

I guess there is a problem with the my config server.

Do you have any idea ?


Thank you Smile

Which deployment tool do you recommend

$
0
0
Hi everyone,
deploying to online dev and production server takes a lot of my time.
What software do you use to deploy? Opensource or small team solutions preferred.
Appreciate your feedback!
Thanks! Jan

sessions and ubuntu

$
0
0
Today I discovered something, that Ubuntu (and Debian) do their own PHP sessions garbage collection but that sessions not prefixed by 'sess_' are ignored. So the CI default session name of 'ci_session' never gets deleted, on my ubuntu 18.04 box they can be found in /var/lib/php/sessions. The script /usr/lib/php/sessionclean which run every half hour does the cleaning and it was in there that I saw the prefix requirement.

upload library processing with wrong mime type

$
0
0
First, thanks for providing such a wonderful framework. I'm new here, don't know about many rules of the forum so sorry in advance.


I found the custom mime is not working and also, the _file_mime_type() not working correctly.

Basically if i upload any apk file then the mime should be "application/vnd.android.package-archive" but program returning only "application/zip". Maybe i'm wrong(i know that this wonderful framework is developed by the best php experts around the globe) but please help me to understand how i can deal with it.

I started debugging and landed on this function. Here is the code:

      if (function_exists('finfo_file'))
      { 
         $finfo = @finfo_open(FILEINFO_MIME);
         if (is_resource($finfo)){
            $mime = @finfo_file($finfo, $file['tmp_name']);
            finfo_close($finfo);

            if (is_string($mime) && preg_match($regexp, $mime, $matches))
            {
               log_message('error', json_encode([$mime, $matches,$matches[1]]));
               $this->file_type = $matches[1];
               return;
            }
         }
      }

A base for a website redesign

$
0
0
Hi here,

I write to you because I need your opinion.

I created in 2011 a website based on CI 2 and now it's time for me to review its design and features.
In order not to start from scratch, I wanted to migrate to Wordpress but as I can't do what I want, I will make these improvements with CI 3 (or CI 4?).

However, to avoid starting from scratch, is there a CMS-like creation (which already includes Bootstrap, a back office, a user management, an internal mail system, ...) available somewhere?

After some research, I found solutions like FuelCMS, CSZ CMS or few sources on Envato Market ...

Do you have any ideas or solutions to offer me to help me redesign my website?

Thank you in advance for your help.

Session error

$
0
0
Keep getting this error intermittently. Does anyone have any thoughts?

<br />
<b>Fatal error</b>:  session_start(): Failed to initialize storage module: user (path: tcp://127.0.0.1:6379) in
<b>/system/libraries/Session/Session.php</b> on line
<b>140</b>
<br />
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    <h4>A PHP Error was encountered</h4>
    <p>Severity: Error</p>
    <p>Message:  session_start(): Failed to initialize storage module: user (path: tcp://127.0.0.1:6379)</p>
    <p>Filename: Session/Session.php</p>
    <p>Line Number: 140</p>
    <p>Backtrace:</p>
</div>

Controllers and methods?

$
0
0
Hi guys

Bit of a weird one here.

Just wondering if there is any way of getting a list of all the controllers and methods that are currently located in the app folder?

Before you say, well you put them there, yeah I know Big Grin , need an automated way for an idea I just had.

Thanks

Calling a MySql function

$
0
0
I have created a function in mysql called NextVal that requires a string parameter and returns an integer.
I tried the following code:
Code:
public function next_value() {
    $ci =& get_instance();
    $sql = 'SELECT nextval(?) as receipt_id';
    $query = $ci->db->query( $sql, array( $this->sequence_name ) );
    return $query->row()->receipt_id;
}

Codeigniter logs the following error:
ERROR - 2019-04-28 19:16:55 --> Query error:  - Invalid query: SELECT nextval('receipt_id_seq') as receipt_id

However, if I paste and run the select statement shown in the error in MySql Workbench it returns the expected integer value under the column name receipt_id

PHP 7.3.5 Released

$
0
0
PHP 7.3.5 Released - Security and Bug Fixes.

how to obfuscate and encrypt the codeigniter application

$
0
0
I want to obfuscate or encrypt the source code of codeigniter application,
how we can do this.
Please provide any solutions.

thanks 
ravi Sad

sending email via gmail

$
0
0
I'm trying to send emails with gmail attachment but codeigniter always gives me the error:
to: 555 5.5.2 Syntax error. n2sm18426280wra.89 - gsmtp
The following SMTP error was encountered: 555 5.5.2 Syntax error. n2sm18426280wra.89 - gsmtp
in any case, however, the email arrives correctly at its destination!
below is the code I use to send

PHP Code:
function sendEmail($to ''$subject  ''$body ''$attachment '') {
 
       
    $controller 
=& get_instance();
 
       
    $controller
->load->helper('path'); 

 
   // Configure email library

 
   $config = array();
 
   $config['useragent'           "CodeIgniter";
 
   $config['mailpath'            "/usr/bin/sendmail"// or "/usr/sbin/sendmail"
 
   $config['protocol'            "smtp";
 
   $config['smtp_host'           "ssl://smtp.gmail.com";
 
   $config['smtp_port'           "465";
 
   $config['smtp_timeout'        '30';
 
   $config['smtp_user'           "text@gmail.com";
 
   $config['smtp_pass'           "password";
 
   $config['mailtype'            'html';
 
   $config['charset'             'utf-8';
 
   $config['newline'             "\r\n";
 
   $config['crlf'                "\n";
 
   $config['wordwrap'            TRUE;
 
   $config['allowed_types'       'pdf';
 
   $config['max_size'            '100000';

 
   $controller->load->library('email');

 
   $controller->email->initialize($config);   
    $controller
->email->set_newline("\r\n");
 
   $controller->email->set_crlf("\r\n");
 
   if($attachment != '')
 
   {
 
       $controller->email->attach(base_url()."uploads/interventi/" .$attachment);
 
   }

 
   $controller->email->from('text@gmail.com','Test Test');
 
   
    $controller
->email->to($to,$to);
 
   
    $controller
->email->subject('Test message');

 
   $controller->email->message($body);    


 
   if($controller->email->send()){
 
       $this->session->set_flashdata('msg''Email sent correctly');
 
   }
 
   
    else
    
{
 
       show_error($controller->email->print_debugger());
 
       
    
}

ci_session with multiple database not working

$
0
0
I am working on a project where using two databases. My requirement is that, Depending on user login type load database e.g.

For user type 1 load db1(default database) Or For user type 2 load db2. Problem is that if login with user type 1 then logged in successfully but if login with user type 2 then login failed due to the ci_session table. how to fix this issue.

Merging CodeIgniter and NoNonsense Forum

$
0
0
I'm using CodeIgniter, and would like to offer users a simple forum to discuss their business. For example the (1) Leader/Director of a company may want to discuss internal business with the (2) Manager, and the (3) Foreperson, and the (4) Workers/Salespersons, and where all other users of the website would be denied access, and I thought NoNonsense Forum (NNF) would be ideal. http://camendesign.com/code/nononsense_forum

I have downloaded the Zip folder, unzipped and read the text files particularly INSTALL.txt but I'm confused on how I would get it to work. I note that the .htaccess file is necessary for NNF to work, and the same named file is also necessary for CodeIgiter to work. That file is located in C:\xampp\htdocs\application\.htaccess and the contents of that file are as follows;

PHP Code:
<IfModule authz_core_module>
Require 
all denied
</IfModule>
<
IfModule !authz_core_module>
Deny from all
</IfModule>` 

I thought the appropriate place to paste the "contents" of NNF folder would be C:\xampp\htdocs\application\ but the two .htaccess files would conflict, however I thought there maybe a possibility they could be amalgamated.

I already have placed the folder in C:\xampp\htdocs\application\NoNonsenseForum-master

I have created a "view" page such as C:\xampp\htdocs\application\views\world\johndoesalesforum.php

Having said all of that I have no idea on how to implement NNF into CodeIgiter and get it to work.

Can anybody please guide me?

Disable Query Builder + Support of IgnitedQuery

$
0
0
Hello,

I am updating Codeigniter from 2.1.4 to 3.1.10 and I ran into the problem, that there is a mixup of the Query Builder with this library: https://github.com/bcit-ci/CodeIgniter/w...itedRecord which worked fine for 2.x, but now it always wants to use the 3.x Query Builder.


So question #1: Is IgnitedRecord & -Query still supported for 3.x or does one have to rewrite the whole database access to the Query Builder? I'm new to the framework, so I also don't know all details or the amount of work that would be.

I already disabled the query builder in the database config as it says in the documentation (https://www.codeigniter.com/user_guide/d...ilder.html) to prevent this, but I get this error:
Query Builder not enabled for the configured database. Aborting.

That doesn't make sense to me, because the documentation explicitly states that you can disable this class without problems. 

Can anyone help me with this? Or do you have a suggestion how to solve that? Thank you!

Greets
Viewing all 14353 articles
Browse latest View live


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