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

Two different 404 error pages problem.

$
0
0
Hello, guys.

I' m facing a very confusing problem with my CI project. I've searched the internet and couldn't find anything useful.

The thing is the 404 error page.

I've created a custom 404 page and replaced it in "Routes" file..

I've also have two different types of controllers.. One for numeric values in url and the regular one for the pages..

Now as for the localhost:

If i access a url that contains numeric value and does not exist like, "localhost/example/123456", the 404 page that shows up is the one that's located under "application/views/errors/html/error_404.php"..


If i access a url that contains text like, "localhost/example/examplepage" and does not exist, the 404 page that shows up is my custom one.

As for the live server:

If i access a link that either contains text or numeric value i get the "application/views/errors/html/error_404.php" page and not my custom one BUT in numeric value url the page is shown css styled with "base_url()" working ok, but in text value url i get the following error: 

Code:
Message: Call to undefined function base_url()

My "routes" file:

Code:
//Other routes

$route['(:num)'] = 'entries/index/$1';
$route['(:any)'] = 'pages/$1';

$route['default_controller'] = 'pages/index';

$route['404_override'] = 'c404';
$route['translate_uri_dashes'] = FALSE;

Any ideas? What am i doing wrong on that?!


triggerFilter in Event

$
0
0
I added below new method code in Events\Events.php

PHP Code:
   /**
     * Runs through all subscribed methods running them one at a time,
     * until either:
     *  a) All subscribers have finished or
     *  b) a method returns false, at which point execution of subscribers stops.
     *
     * @param $eventName
     * @param $value
     * @param $arguments
     *
     * @return mixed
     */
 
   public static function triggerFilter($eventName$value, ...$arguments)
 
   {
 
       // Read in our Config/events file so that we have them all!
 
       if ( ! self::$initialized) {
 
           self::initialize();
 
       }

 
       $listeners self::listeners($eventName);

 
       foreach ($listeners as $listener) {
 
           $start microtime(true);

 
           $value = static::$simulate === false
                
$listener($value, ...$arguments)
 
               true;

 
           if (CI_DEBUG) {
 
               static::$performanceLog[] = [
 
                   'start' => $start,
 
                   'end' => microtime(true),
 
                   'event' => strtolower($eventName)
 
               ];
 
           }

 
           if ($value === false) {
 
               return false;
 
           }
 
       }

 
       return $value;
 
   


PHP Code:
    public function test_method()
    {
    
    $data = [
            'raw1' => 'Before Text',
            'raw2' => 'aaaa1234',
        ];

    
    \CodeIgniter\Events\Events::on('test_event1', function ($value$data2$data3) {
            $value['raw1'] = 'After event~!';
            $value['raw2'] = strtoupper($value['raw2']) . $data2;

            return $value;
        }, EVENT_PRIORITY_HIGH);

        \CodeIgniter\Events\Events::on('test_event1', function ($value$data2$data3) {
            $value['raw1'] = $value['raw1'] . ' // One more!';
            $value['raw2'] = $value['raw2'] . $data3;

            return $value;
        }, EVENT_PRIORITY_NORMAL);

    
    $data2 = \CodeIgniter\Events\Events::triggerFilter('test_event1'$data'_TITLE''_SUBJECT');

    
    var_dump$data );
    
    echo '<br>';
    
    var_dump$data2 );

    
    ///////////////

        \CodeIgniter\Events\Events::on('another_event', function ($value) {
            $value['raw1'] = 'After event~!';
            $value['raw2'] = strtoupper($value['raw2']) . ' First';

            return $value;
        }, EVENT_PRIORITY_HIGH);

        \CodeIgniter\Events\Events::on('another_event', function ($value) {
            $value['raw1'] = $value['raw1'] . ' // One More!';
            $value['raw2'] = $value['raw2'] . ' Second';

            return $value;
        }, EVENT_PRIORITY_NORMAL);

        $data2 = \CodeIgniter\Events\Events::triggerFilter('another_event'$data);

        echo '<br>';
        var_dump$data );
        echo '<br>';
        var_dump$data2 );
    


Because I need something similar to the filter that Wordpress uses.
What do you think about this?  Please, let me know your opinions.

Block IP

$
0
0
Hi
I need block some users when i disable or disactive their
I know i have to add ip to htaccess but when the number of IPs is high so htaccess is not good idea
Do you have idea?
I need user dont access to server

Routing without index.php

$
0
0
Hello


I am trying to have a route like http://website/all

I put this in my routes:
$route['all'] = "index/all"; //controller / function

And it says in the specs that this should route me to 
website/all 
but is not doing that.
That route is actually working with an index.php like website/index.php/all

So how do I get rid of the index.php pls?

Is CodeIgniter 3 died?

$
0
0
Hi Guys,
Usually every 2 or 3 month, a new version of CodeIgniter3 released.
But Since the version 3.1.9 nothing happen, and there is no activity on GitHub since Sep 10.
I'm planning to start a new protect, and I d'ont know if I should go for CodeIgniter3 and I'm worry if CI3 is died, or Still wait CodeIgniter4.
Thanks In advance,

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?

session problem

$
0
0
hi i'm using ci-version 3.19 and i am having problem in session . 

sceneraio:

i have loaded session libraray in config folder and  controller.

 public function __construct() {
parent::__construct();
    $this->load->library('session'); 
   $this->load->model('product_model');
    
 }


problem: after initialising session in one controller i am n't able use the session id for another controller and  nor i am able to use it in different page.

Run php script without hanging

$
0
0
Hi
I have function that send push notification to users
When i use this function when user use it,it take 2 second for send push and user give result
While after execute send_push function,user have to receive result quickly
Do anyone have idea?

PHP Code:
function send_push($topic,$data,$is_android TRUE) {

        
//shell_exec("php test.php $topic '$data' > /dev/null 2>/dev/null &");

        
$api    =    config_item('firebase_api');

        
$fields = array
        (
            
'to'                 => "/topics/$topic",
            
'content_available'    =>    TRUE,
            
'data'                => $data
        
);

        if (!
$is_android)
            
$fields['notification']    =    $data;
        
        
$headers = array
        (
            
'Authorization: key=' $api,
            
'Content-Type: application/json'
        
);

        
$ch curl_init();
        
curl_setopt$ch,CURLOPT_URL'https://fcm.googleapis.com/fcm/send' );
        
curl_setopt$ch,CURLOPT_POSTtrue );
        
curl_setopt$ch,CURLOPT_HTTPHEADER$headers );
        
curl_setopt$ch,CURLOPT_RETURNTRANSFERtrue );
        
curl_setopt$ch,CURLOPT_SSL_VERIFYPEERfalse );
        
curl_setopt$ch,CURLOPT_POSTFIELDSjson_encode$fields ) );
        
$result curl_exec($ch );
        
curl_close$ch );
        return 
$result;

    } 

Forum Policy Changes Feedback Requested

$
0
0
I am looking for community feedback on possible policy changes, through the survey at the top of this post.
Not all of the items are easy to implement, or necessarily practical, but I would like to know which of them the community supports.
They have been ordered alphabetically, and not in any implied order of importance.

Please take a few minutes, and checkoff those policies you agree with for forum management.
I will report any actions we take as a result.

Current forum policies:
Quote:Please use English, and proper English at that.
Be respectful of others; personal differences should be handled elsewhere.
Do not use this forum to promote your non-related business.
Offensive language will not be tolerated. Spam is offensive.
It's a good idea to check if your question has been answered already.
Use meaningful titles when creating new threads.
Stay on topic.
Do not knowingly post copyrighted material.
If you want to format your posts, or to include code in them, use MyCode tags.

Reminder: newly registered users have their first two posts moderated. This may take a few hours or a few days, depending on what the volunteer moderators are up to.


Current moderation practices for policy implementation:
- purge blatant spammers (posts, site, signature)
- warn users re off-topic posts, spammy looking posts / sigs
- warn/purge thread hijackers

Why call session not working?

$
0
0
my config is like this :
Code:
$config['sess_driver'] = 'database';  // select database driver
$config['sess_save_path'] = 'ci_sessions';  // name of the mysql table
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']  = 300;

My autoload is like this :
Code:
$autoload['libraries'] = array('database', 'session', 'form_validation', 'functions');

In controller login.php :
Code:
$this->session->set_userdata('club', 'chelsea');

In controller dashboard.php :
Code:
echo $this->session->userdata('club');

It did not succeed in calling the session club if a different controller
But, when I call session club in the same controller(controller login.php), it's working
I try 
Code:
$this->library->load('session');

 in the constructor of 

Code:
Dashboard.php

. But it's not a success

Any solution to solve my problem?
Thank you

DB Query Question

$
0
0
Hi,

I have a MySQL table with: user.id, user.name, user.refer_id

I would like to query the DB once passing the user.id value, but i would like to use the same query to retrieve the refer name based on his ID too. It is possible?

Basically i want to get the user based on his ID and consequently the 'Refer Name' of that user based on the refer_id.

Table Example:

ID     Name     Refer_id
1       John       2
2       Alex        3
3       Peter       1

Executing stored procedure with output

$
0
0
Hi All,

Kindly help me on my issued regarding stored procedure.

I have a query (SP) on SSMS which is working fine but when running on codeigniter it returns blank result.

SSMS

[Image: capture.jpg]

Codeigniter

Model
public function call_receiving($receipt_key,$line_no,$accident_code,$sku,$pid,$qty)
  {
     $this->output->enable_profiler(TRUE);                           //CI Profiler
     $query = $this->db->query("
     begin
     DECLARE @n_err int,
           @c_errmsg varchar(255)
     
     EXEC   [dbo].[SCH_SME_INBOUND_RECEIVING_SCAN]
           @c_receiptkey = N'{$receipt_key}',
           @c_receiptlinenumber = N'{$line_no}',
           @c_accidentcode = N'{$accident_code}',
           @c_scansku = N'{$sku}',
           @c_id = N'{$pid}',
           @n_qty = {$qty},
           @c_userid = N'{$rfuser}',
           @n_err = @n_err OUTPUT,
           @c_errmsg = @c_errmsg OUTPUT;
     
     SELECT @n_err as N'@n_err',
           @c_errmsg as N'@c_errmsg'
      end
      ");
     return $query->result();
  }

Controller
public function call_receiving()
  {
     $receipt_key = $this->input->post('receipt_key');
     $line_no = $this->input->post('line_no');
     $accident_code = $this->input->post('accident_code');
     $sku = $this->input->post('sku');
     $pid = $this->input->post('pid');
     $qty = $this->input->post('qty');
     $result = $this->main->call_receiving($receipt_key,$line_no,$accident_code,$sku,$pid,$qty);
     //$result = $this->sp->sqlsrv_runSP("SCH_SME_INBOUND_RECEIVING_SCAN",$params);
     echo json_encode(array('status'=>true,'result'=>$result));

  }



Result
{"status":true,"result":[]}

CI 3.1.9 session timeout issue

$
0
0
My company project runs on CI 3.1.9 version. When there are many users logging into the system, then after some time session automatically gets timeout. I have increased the session expiration and session update in config.php. But same issue(session timeout) is happening everytime. Please help.

Using GraphQL with CL3

$
0
0
Has anyone used GraphQL with CL3, and maybe have an example of how this works? I want to build a REACT front end, maybe there is a better way for React to talk to CL?

Defer helper output - possible?

$
0
0
I am still trying to optimise my site and noticed that my contact form's fileupload (fileinput.js from Krajee.com) causes a huge delay on the FCP time. This form however is below the fold and added where needed through a helper function.

The additional JS is what is slowing it down, if I remove it and use the fallback non-ajax upload I can improve FCP my about 2seconds.

So I was thinking why not just defer the loading of this form in the helper by a second or so to allow an immediate FCP and then lazy-load the form?

I have however no clue how I could do or how to the change the helper function to do so. 


Has anyone done a delay for the output (how?) or should I simply put the script part into an external JS and put that external js-file with a defer tag in the $return sting and see what happens?

How to set Pagination's Base URL?

$
0
0
How to set Pagination's Base URL? I read the documentation but didn't find any information about it

Adding property in all Contrellers: MY_Controller vs BaseController

$
0
0
I would like each controller in my app to have a property called $controller_url that I would set to

$this->config->item('base_url') . $this->uri->segment(1);

In this way in each controller I will always have the controller url ready to be passed to views.



What's the best practice to do this?

Should I add an application/core/MY_Controller.php

Code:
class MY_Controller extends CI_Controller
{  
   protected $controller_url;
  
   function __construct() {
      parent::__construct();      
      $controller_url = config_item('base_url') . $this->uri->segment(1);      
   }

}

, or should I simply create a sort of base controller and extends all my controllers from that one i.e.

application/controllers/basecontroller.php

Code:
class BaseController extends CI_Controller
{  
   protected $controller_url;
  
   function __construct() {
      parent::__construct();
      $controller_url = config_item('base_url') . $this->uri->segment(1);      
   }

}

class Invoices extends BaseController
{  
   function __construct() {
      parent::__construct();
   }

   function listInvoices() {
      $vars['year'] = $year;
      $vars['controller_url'] = $this->controller_url;
      ...
      $this->load->view('invoices_v.htm', $vars);
}

What do you think?

null coalescing operator in url_helper

$
0
0
hey,
im wondering why aren't using the ?? operator in url_helper for config selection
there are some situations where we already use it - but not for config detection
currently:

PHP Code:
$config = empty($altConfig) ? config(\Config\App::class) : $altConfig
with ??

PHP Code:
$config $altConfig ?? config(\Config\App::class); 


i know that the different is tiny but the code looks much cleaner and short Wink

Change default page for csrf error

$
0
0
Where to change default page for "this action is not allowed" which is caused by csrf token expired?

Any good google maps libraries?

$
0
0
Hey guys,
I'm trying to add google maps functionality in my project and i was wondering if there's anything out there since i found this:

https://github.com/BIOSTALL/CodeIgniter-Google-Maps-V3-API-Library

But as it seems they abandoned the project.

If anyone has any propositions on this please feel free to suggest, or if you have used the above i'd like to ask some things that there are not in the documentation.

Thank you in advance!
Viewing all 14072 articles
Browse latest View live


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