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

How to have shared libraries and helpers between applications in CodeIgniter 3

$
0
0
Assume the following situation:

- 2 applications using 1 CodeIgniter installation under the same URL
- The requirement to share libraries and helpers (and maybe more) between application
- and...reduce redundant code

PS. change the server names below to your own situation!

Code:
- CodeIgniter-3.1.10 <- framework, don't change anything here
 - ....
- server <- 1. server
 - application
   - ...
- server_other <- 2. server
 - application
   - ....
- server_common <- package with the shared code
 - libraries
 - helpers

How to do it?

In the index.php of both servers (not the common one):

Code:
// $system_path = "system";
$system_path = dirname( __FILE__, 2 ) . '/CodeIgniter-3.1.10/system';

In the autoload.php of both servers you add the following:

Code:
$autoload['packages'] = [dirname(__FILE__, 4) .'/server_common'];
$autoload['libraries'] = [...];
$autoload['drivers'] = [... ];
....

Sample of a common library "Itworks.php" in folder "libraries" of "server_common":
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Itworks
{
   function show()
   {
       echo 'it works great';
   }
}

Sample of a controller calling the "show" function in either of the other servers:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Valhalla extends CI_Controller
{
   public function __construct()
   {
       parent::__construct();

       $this->load->library('itworks');
   }

   public function itworks() {
       echo $this->itworks->show();
   }
}

As you can see, once loaded it works like a normal library.
And, you can still load the local libraries on the server too.

Now use in your browser:
Code:
https://www.yourserver.com/server_other/valhalla/itworks
showing: 'It works great'

What's the CI4 big change?

$
0
0
Hi,

I'm a CI developer for some years now. Where can I find the motivation of making a "new" CI 4? I mean, what's the big change from previous version? Architecture change? New feature? What we need to know about migrating from 3.x to 4.x?

Thx

Microsoft sql server

$
0
0
All,

Is there a date that Microsoft SQL driver is updated for Codeigniter 4?
I need that for one project the other projects are Postgresql and that works perfectly.

André

fix modular hmvc with twig

$
0
0
Hi everyone,
I'm integrating Twig Template library in CI with HMVC. Everything is working fine but not when i load view from module.
I need inherit from a base template in all my templates, and be able to load view from module.

How can I retrieve current module "views" path in the library??

How to clear the cache for particular URL?

$
0
0
Hi All,

How to clear the cache for a particular page. I can clear the entire cached files from 'cache' folder but I don't how to clear the cache for a particular page. Please help me with this.

Thanks in advance.

url suffix problem in nginx

$
0
0
I tried to add .html extension to my page by configuring $config['url_suffix'], it works fine in apache however in nginx I got a 404 error. I did a lot of research on google and still cannot resolve this issue. Any help thx

Does ci4 need the route cache feature?

$
0
0
Like the laravel route cache  url:https://laravel.com/docs/5.7/controllers#route-caching


It say: Using the route cache will drastically decrease the amount of time it takes to register all of your application's routes. In some cases, your route registration may even be up to 100x faster.

Asking, does ci need to develop this feature?

Search query using multiple tables

$
0
0
Hi, have looked online for a while to find a solution for this but can't find anything specifically related to my question so posting here.

I'm building an e-commerce site that includes a search bar.

The products in my database are set up as follows:

products

Code:
id   product_title           product_cat   product_sub_cat

16   'Robin Red Breast'      3             6

product_cats
Code:
id      cat_name

3       animals
4       plants

product_sub_cats

Code:
id      sub_cat_name

6       birds
7       fish


I'm trying to find products that are related to a search query. At the moment, the search query looks in the products table for any products that contain anything similar to the query in their title field. E.g:

Code:
$this->db->from('products');
$this->db->like('product_title', $query);
$results = $this->db->get()->result();


What I want to do, is also use the query to search the category and sub-category tables and find any categories which have a similar name to the search query, then fetch any products that are in this category. For example, at the moment, the search query 'Robin Red' will find the 'Robin Red Breast' product, but searching for 'birds' does not return anything.

What would be the best way of going about making the latter possible using active record?

Does this mean searching the cats and sub_cats tables separately, fetching the id's of any rows that match the query, then selecting any rows from the products table that match the id('s)?


Cheers!   Smile

muti domain support.

$
0
0
Hi,

In CI3 , it was:

    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
    $ssl_set = "s";
    } else {
    $ssl_set = "";
    }
    */

    //$config['base_url'] = 'http'.$ssl_set.'://'.$_SERVER['HTTP_HOST'];

in CI4, if statements do not seem to work and give a 500 error.
What is the best way to use/detect multiple subdomains/domain ?

    public $baseURL = ??


The SaaS application that I am trying to port from CI3 works like

subdomain1.domain.com
subdomain2.domain.com ..   -- can also be mapped to domain2.com 



I am checking how to achieve the same in CI4 ?


Thanks,

CI_DB_mysqli_result->_fetch_object()

$
0
0
Stack trace:
#0 /home/system/database/DB_result.php(259): CI_DB_mysqli_result->_fetch_object()
#1 /home/system/database/DB_result.php(409): CI_DB_result->result_object()
#2 /home/system/database/DB_result.php(335): CI_DB_result->row_object(0)
#3 /home/system/libraries/Session/drivers/Session_database_driver.php(425): CI_DB_result->row()
#4 /home/system/libraries/Session/drivers/Session_database_driver.php(282): CI_Session_database_driver->_release_lock()
#5 [internal function]: CI_Session_database_driver->close()
#6 [internal function]: session_write_close()
#7 {main}

Any have ideas?

Is it good to use CI 3.x for new eComm development

$
0
0
Hi All,

Am gonna develop a e Comm website , and i have chosen CI as my choice. It has been couple of years i have done development in CI. I am seeing 2 versions of CI in download option. 2.x and 3.x. I saw 3.x is still in development. my question here is, Can i download CI 3.x and start my development? Is it safe to start my development using this or should i go with older version?

Also i will CI support react components ? anyone tried experimenting this? 


Please share your thoughts.

Thanks in advance

Thanks,
Anbarasu R

Is the template folder needed for the tutorial?

$
0
0
Hi,

In the CodeIgniter tutorial, specifically at

https://www.codeigniter.com/userguide3/t...pages.html

, the instructions say to create the page header and footer in the

   ../application/views/templates folder.


, it doesn't mention creating the templates folder.  It just says to put the files in that folder.


The problem is that the CodeIgniter 3 distribution doesn't have a templates folder.  
It has only the parent folder,

   ../application/views


So the directive on that page, to point the browser to


[your-site-url]index.php/pages/view



, doesn't work.  It returns a 404.  I assume it's because CodeIgniter isn't using that templates folder, 
where the header and footer are located.


It also returns a 404, if I copy the header.php and footer.php files from the templates folder back into
it's parent views folder.


Summary, long story short: I think the tutorial is mistaken, when it instructs the student to using the ../views/templates folder.


Regards,

Routing in Multilanguage website

$
0
0
Hi,
I have found several examples of routing in web but in my case they did not work.
I used this code for routing:
PHP Code:
$route['^(\w{2})/(.*)$'] = '$2';
$route['^(\w{2})$'] = $route['default_controller']; 
but this code does not work when I use url aliases:
PHP Code:
$route['login'] = 'auth/login';
$route['logout'] = 'auth/logout'
for example, in this case 
this https://www.mydomain.com/tr/auth/login url works, 
but https://www.mydomain.com/tr/login this one does not work. 
Can anyboldy help me with it?

Thanks in advance

form_validation return after first field error ?

$
0
0
Hi, so recently i started to use CI, and im at a point where i need to validate my forms and i have a question

Is there a good reason for this code ?
Code:
if ( ! isset($this->_error_array[$row['field']]))
{
    $this->_error_array[$row['field']] = $message;
}

return;

(Line 814 @ system/form_validation).

I don't want to piss off visitors just with one field error, i want to show then all.

Quote:I want to get this:
 ["xxx"]=>
 array(2) {
   [0]=>
   string(72) "The xxx field must be at least 3 characters in length."
   [1]=>
   string(72) "The xxx field does not match the yyy field."
 }

Not this:
 ["xxx"]=>
 array(1) {
   [0]=>
   string(72) "The xxx field must be at least 3 characters in length."
 }

So from the code above i'm now using only this
Code:
$this->_error_array[$row['field']][] = $message;

Github Project URL Suggestion


Static Route / predefined variables

$
0
0
I am trying to setup a route that sets a fixed parameter

PHP Code:
$routes->get('/''Pages::showme/first');
$routes->get('pages/showme/(:alphanum)''Pages::showme/$1'); 

hitting "/" results in

Code:
Controller method is not found: showme\first

But "/pages/showme/first" works as expected

I have read the route manual but have not found a way to do it, any help is greatly appreciated

Problem with passing values to bootstrap modal window

$
0
0
I am just start creating a database update system with a bootstrap modal window. I am using ajax to populate the modal form fields but not getting any value. Please review the code and help me to figure out the error.

 HTML Code
Code:
<!-- Modal -->
        <div class="modal fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">Edit Data</h4>
                  </div>
                  <div class="modal-body">
                      <div class="content-wrapper content-wrapper--with-bg">
                      <?php echo form_open('quotation'); ?>
                           <p>
                            <input type="text" name="bname" id="bname" required class="form-control custom-ctrl" placeholder="Billing Name">
                           </p>  
                           <span class="text-danger"><?php echo form_error('bname'); ?></span>
                           <p>
                            <input type="text" name="company" id="company" required class="form-control custom-ctrl" placeholder="Company">
                           </p>
                           <span class="text-danger"><?php echo form_error('company'); ?></span>
                            <input type="hidden" name="id" id="id"> 
                            </p>
                            <button type="submit" id="update" class="btn btn-primary btn-custom pull-right"> Update</button>
                            <br>
                        <?php echo form_close(); ?>
              </div>
            </div>
          </div>
        </div>
      </div>

My Controller

PHP Code:
public function fetch_by_id(){
    $this->load->model("quotation_model");
    $result $this->quotation_model->fetch_by_id();
    echo json_encode($result);   


And Here is the Modal associated with the controller.


PHP Code:
public function fetch_by_id(){
    $id $this->input->get('id');
    $this->db->where('id'$id);
    $query $this->db->get('quotes');
    return $query->result();



I am just able to popup the modal window but not getting any value

num_rows() problem in the count_all_results

$
0
0
Hi guys,

I use the count_all_result function, and if I set a non existent column name in WHERE clause, then throw an error.
In the WHERE clause have dynamic column name, so incorrect column names may occur

Code:
$this->db->select('column_1');
$this->db->where('nonexist_col', 'anything');
$count = $this->db->count_all_results('table');

Error: Call to a member function num_rows() on a non-object
This is in the count_all_results function of DB_query_builder.

Code:
public function count_all_results($table = '', $reset = TRUE)
{
        ...
    ...

    if ($result->num_rows() === 0)
    {
        return 0;
    }
Because the query string wrong, the $result will have no num_rows function.
Here is a possible solution, but I don't want to overwrite the CI code:

Code:
if(is_object($result)){
        if ($result->num_rows() === 0)
    {
       return 0;
    }
}
else{
    return FALSE;
}

Is there any good solution for this?

Matching data from 2 table with validation date

$
0
0
At this time I have data from the database, results of the join data table users and table campaigns, like this :

ID
001
005
008

and I have data from table incomes, like this :

id       name      date
1        001        2018-10-10
2        005        2018-10-10
3        008        2018-10-10
4        001        2018-10-11

how to check the results of the join data in table incomes?

if the data ID is not the same as the data name on 2018-10-11, the results will be obtained :

ID
005
008

The question: what query should I use and what method do I need to apply in the controller / view. if the masters here are willing to include with simple code it is very very valuable to me.

thank you, greetings coding.

How often do you use the backup() method of the database drivers?

$
0
0
The Mysql driver in CodeIgniter (I think that's the only one) has a backup feature. Do you ever use this feature? Thinking of dropping it from CI4.
Viewing all 14343 articles
Browse latest View live


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