Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 24,629
» Latest member: situstototogelterpercaya
» Forum threads: 73,483
» Forum posts: 375,927

Full Statistics

Latest Threads
ci_session cookie rejecti...
Forum: CodeIgniter 4 Support
17 minutes ago
» Replies: 8   » Views: 3,498
Databases: searching for ...
Forum: General Help
31 minutes ago
» Replies: 11   » Views: 341
Class not found
Forum: General Help
51 minutes ago
» Replies: 1   » Views: 41
CodeIgniter v4.1.2 releas...
Forum: News & Discussion
9 hours ago
» Replies: 11   » Views: 453
update(null,$data)
Forum: CodeIgniter 4 Support
10 hours ago
» Replies: 1   » Views: 51
get and post filtering fo...
Forum: CodeIgniter 4 Discussion
Today, 08:50 AM
» Replies: 5   » Views: 128
Swith to object oriented ...
Forum: General Help
Today, 08:45 AM
» Replies: 10   » Views: 585
The requested URL was not...
Forum: Addins
Today, 07:53 AM
» Replies: 0   » Views: 43
No sessions in testing en...
Forum: CodeIgniter 4 Support
Today, 07:26 AM
» Replies: 3   » Views: 41
Looking for CI developer ...
Forum: Jobs
Today, 07:25 AM
» Replies: 2   » Views: 91

 
  Swith to object oriented programming
Posted by: blab99778 - 05-05-2021, 10:53 AM - Forum: General Help - Replies (10)

Hi! I have used CodeIgniter 3 to develop my first web app. I learnt programming (including object oriented programming) years ago but never used in a real application. I have already finished my first working web app but I think I didn't use OOP. I don't make myself clear with how to use it, so I will try to post a short summary of what I have programmed (only what is necessary to understand my approach) and, please, I would like to know how it should look in OOP, if it is worth doing that change to make it easier to add functionality in the future..

MODEL:

PHP Code:
<?php
class Customer_model extends CI_Model
{
    public function __construct()
    {
        $this->load->database();
    }

    public function getCustomers()
    {
        
$result $this->db->get('customers')->result();
        return 
$result;
    }

    public function getCustomer($id_customer)
    {
        
//database sql
        
        
$customer $query->row();        
        return $customer;
    }

    public function getInvoices($id_customer)
    {
        //database sql
        
        $query $this->db->get();
        return $query->result();
    }



CONTROLLER:
PHP Code:
<?php
class Customers extends CI_Controller {
  
    
public function __construct()
    {
        parent::__construct();
        $this->load->model('customer_model');
    }
    
    
/*
        Show all customers. From this page the detail of one customer can be accessed (calling to the next function)
    */    
    
public function index()
    {
        
$data['customers'] = $this->gestion_model->getCustomers();
        
$this->load->view('customer/all'$data);
    }
  
    
/*
        Show one customer with his/her invoices
    */
    
public function customer($id_customer)
    {
        
$data['customer'] = $this->gestion_model->getCustomer($id_customer);
        
$data['invoices'] = $this->gestion_model->getInvoices($id_customer);
        
$this->load->view('customer/detail'$data);
    }




The customer/all view:
PHP Code:
<?php foreach($customers as $customer): ?>
<tr>
    <td><?php echo $customer->id?></td>
    <td><?php echo $customer->name?></td>
</tr> 



And the customer/detail view:
PHP Code:
<?php echo $customer->id?></td>
<?php echo $customer->name?></td>
<?php foreach($invoices as $invoice): ?>
<tr>
    <td><?php echo $invoice->date?></td> 


The full views and other functions in model and controller (to insert and update data) are not required to undertand how I managed to organize my app.

So, my general question is how to do this app OOP because I understand what I did is not OOP, as I haven't created a "customer" or "invoice" classes. And the particular questions are:
  • Should I define Customer_model as a class representing a customer (with attributes like id, name...), so the class representes ONE customer, or it should represent ALL customers? So, how should I rewrite getCustomers() and getCustomer($id_customer)?
  • Any changes to the controller?
  • Any changes to the views?
Thanks and sorry if this is a very general question, but I really like CodeIgniter and want to fully understand how things should work.


  Trouble with view_cell
Posted by: Zeff - 05-05-2021, 07:25 AM - Forum: CodeIgniter 4 Support - Replies (2)

Hi folks,
I tried to use the view_cell() function in a view file, but I always get an error: 

Code:
TypeError

Return value of CodeIgniter\View\Cell::render() must be of the type string, null returned
My view file is very simple, I just inserted a view_cell() in the default CI welcome_message.php:
Code:
<div class="heroe">
    <h1>Welcome to CodeIgniter <?= CodeIgniter\CodeIgniter::CI_VERSION ?></h1>
    <h2>The small framework with powerful features</h2>
</div>
</header>

<!-- CONTENT -->

<?=view_cell('\App\Controllers\TestController::bar')?>

<section>
    <h1>About this page</h1>

The TestController.php (which has no constructor!) has a simple method:

Code:
public function bar()
{
    echo 'BAR';
}
I use no params, so it's a very simple test but I keep on getting this error!

Many thanks for the golden tip! [Image: wink.png]



Attached Files Thumbnail(s)
   

  How to attach a file without the user being able to explore all files?
Posted by: christaliise - 05-05-2021, 06:43 AM - Forum: General Help - Replies (15)

We have a series of files that are categories & have a system where a user can create an advert, but the only way we can see to attach an advert into the category is by using HTML input type="file" however that gives the user access to all the folders & files in the computer where we would prefer to limit the users access to only files in Adverts folder & under his/her username. We have tried a few snippets of HTML coding to try such limitation but nothing has worked.

Even if we could get some HTML coding to work we do realize that HTML is frontend, similar to Javascript, & suspect that a clever user could manipulate the HTML coding stored in "his/her own browser" & gain access to whatever is desired. We dont want that.

Is there any PHP backend coding that will restrict a user to say the Adverts folder & under his/her username?


  New XAMPP Releases
Posted by: InsiteFX - 05-05-2021, 05:04 AM - Forum: Lounge - Replies (3)

XAMPP 7.4.18 and XAMPP 8.0.5 Released.


  Route call wrong method
Posted by: sfarzoso - 05-03-2021, 10:37 AM - Forum: CodeIgniter 4 Support - Replies (7)

I have this routes:

PHP Code:
$routes->group('admin', function ($routes) {

    
$routes->group('media', [
        
'filter'         => 'permission:manage-media',
        
'namespace'        => 'App\Controllers',
        
'controller'    => 'Media',
        
'except'        => 'show'
    
], function ($routes) {

        
$routes->get('/''Media::index');
        
$routes->delete('(:any)''Media::delete/$1');
        
$routes->post('move''Media::move');

        
$routes->get('(:any)/details''Media::details/$1');
        
$routes->get('filter''Media::filter');

        
$routes->get('directory''Media::directory');
        
$routes->post('directory''Media::directory');
        
$routes->delete('directory/(:any)''Media::directory/$1');
    });
}); 

this is what CI returns:

[Image: YtUQs06.png]

now if I call a delete method for admin/media/1 all works as expected, but when I call admin/media/directory/1

using:

PHP Code:
$.ajax({
    url: `<?= route_to('admin/media/directory') ?>/1`,
    method'DELETE',
}).
done((datatextStatusjqXHR) => {
    Toast.fire({
        icon'success',
        titlejqXHR.statusText,
    });
}).
fail((error) => {
    Toast.fire({
        icon'error',
        titleerror.responseJSON.messages.error,
    });
}) 

this will call the method delete() of the Media controller instead of call the method directory, why?


  Cannot execute query update with multiple rows
Posted by: sfarzoso - 05-03-2021, 08:13 AM - Forum: CodeIgniter 4 Support - Replies (1)

I'm trying to update multiple rows using this code:

PHP Code:
$directoryId $this->request->getPostGet('directory_id');
        $where $this->request->getPostGet('media_ids');
        var_dump($where);
        var_dump($directoryId);
        $result $this->post->whereIn('id'$where)->update('parent'$directoryId); 

essentially $where contains this:

PHP Code:
array(2) {
  [0]=>
  string(4"1115"
  [1]=>
  string(4"1116"


and $directoryId is: 1132

I get:

PHP Code:
Return value must be of type array, string returned 


  trying to require
Posted by: richb201 - 05-03-2021, 04:19 AM - Forum: General Help - Replies (7)

I am trying to use the sendpulse library.  First I tried to load it with Composer but composer complains that I should be using Composer2. When I try to upgrade to Composer2 that fails. So then I tried to manually load. 

I tried

require APPPATH."../vendor/sendpulse-rest-api-php-master/src/Storage/ApiInterface.php";

I am getting this error:
Severity: Warning
Message: require(/app/application/../vendor/sendpulse-rest-api-php-master/src/Storage/ApiInterface.php): failed to open stream: No such file or directory


then I tried:

require "/vendor/sendpulse-rest-api-php-master/src/Storage/ApiInterface.php";
but I get the following:
Message: require(/vendor/sendpulse-rest-api-php-master/src/Storage/ApiInterface.php): failed to open stream: No such file or directory

and then I tried:

require ("sendpulse-rest-api-php-master/src/Storage/ApiInterface.php");

But I get
Message: require(sendpulse-rest-api-php-master/src/Storage/ApiInterface.php): failed to open stream: No such file or directory

I then changed the owner with chown and the permissions with chmod. Now when I ls -l I get:

[email protected]:/opt/docker-substantiator2/app/vendor/sendpulse-rest-api-php-master/src$ ls -l ApiInterface.php

-rwxrwxrwx 1 richb201 richb201 10828 Dec 15 10:25 ApiInterface.php


But I still get:
A PHP Error was encountered

Severity: Compile Error

Message: require(): Failed opening required 'sendpulse-rest-api-php-master/src/Storage/ApiInterface.php' (include_path='.:/opt/bitnami/php/lib/php')
Filename: controllers/Users_start_login.php


Can anyone tell me what is wrong?


Question Multicountry and multilanguage website
Posted by: endriu - 05-03-2021, 12:44 AM - Forum: General Help - Replies (2)

Hi everyone!

I need to develop a multicountry website in which each country can have 1 to 3 languages.
The structure I would like to obtain looks like this:

United States:
example.com/us/en

Germany:
example.com/de/en
example.com/de/de

Switzerland:
example.com/ch/en
example.com/ch/fr
example.com/ch/de

So the URL will consist of: domain/country/language

Furthermore, I will need to be able to customize content based on the selected country.

Could you recommend me a method/tutorial to follow?

Thank you!


  Call to a member function on bool
Posted by: mauroMbs - 05-02-2021, 01:41 PM - Forum: CodeIgniter 4 Support - Replies (2)

I'm stuck on validation.
the "validate" instance does not recognize the "hasError" functions:
returning the error:
Call to a member function hasError () on bool

PHP Code:
$validation $this->validate([
            
'user'    =>'required',
//            'mail'    =>'required|valid_email|is_unique[users.mail]',
            
'mail'    =>'required|valid_email',
            
'pswd'     =>'required|min_length[5]|max_length[12]',
            
'cPswd'    =>'required|min_length[5]|max_length[12]|matches[password]'
        
]);


        if(!
$validation){
        
$usrErr $validation->hasError('user') ? $validation->getError('user') : "";
            echo 
'user: '.$usrErr;                
        }else{
            echo 
"corretto";    

        } 

after seeing and reviewing several tutorials on the subject, I am at a standstill.

I hope to get help from the experts


  Codeigniter 4 IonAuth 4 get logged in user
Posted by: underware - 05-02-2021, 12:04 PM - Forum: CodeIgniter 4 Discussion - Replies (2)

Managed to add ionAuth. How do I get logged in user in views?

PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{
    public function 
index()
    {
        if (!$this->ionAuth->loggedIn()) {
            // redirect them to the login page
            return redirect()->to('/auth/login');
        } else {
            return 
view('welcome_message');
        }
    }

PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Psr\Log\LoggerInterface;

class 
BaseController extends Controller
{

    protected 
$helpers = [];

    public function 
initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);
        
$this->ionAuth = new \IonAuth\Libraries\IonAuth();
    }



  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.