trongate / trongate-framework

The Trongate PHP framework
https://trongate.io
Other
1.12k stars 100 forks source link

Sub Module: SQL creator error in admin template. Version: 1.3.3045 #145

Closed Soliaonline closed 1 year ago

Soliaonline commented 1 year ago

Built the Module with the Trongate app version 1.0.004.
Created categories database that looks like.

https://i.imgur.com/ETqnYi1.png

I have parent::__construct(); however the Trongate class still does not know to call the categories database. Model.php $this->get_table_from_url() is returning blank.

class Categories extends Trongate {

private $default_limit = 20;
private $per_page_options = array(10, 20, 50, 100);    

function __construct () {
    parent::__construct();
    $this->parent_module = 'items';
    $this->child_module = 'categories';
}

 function manage() {

    if (segment(4) !== '') {
        $data['headline'] = 'Search Results';
        $searchphrase = trim($_GET['searchphrase']);
        $params['cat_name'] = '%'.$searchphrase.'%';
        $sql = 'select * from categories
        WHERE cat_name LIKE :cat_name
        ORDER BY id';
        $all_rows = $this->model->query_bind($sql, $params, 'object');
    } else {
        $data['headline'] = 'Manage Categories';
        $all_rows = $this->model->get('id');
    }

    $pagination_data['total_rows'] = count($all_rows);
    $pagination_data['page_num_segment'] = 3;
    $pagination_data['limit'] = $this->_get_limit();
    $pagination_data['pagination_root'] = 'categories/manage';
    $pagination_data['record_name_plural'] = 'categories';
    $pagination_data['include_showing_statement'] = true;
    $data['pagination_data'] = $pagination_data;

    $data['rows'] = $this->_reduce_rows($all_rows);
    $data['selected_per_page'] = $this->_get_selected_per_page();
    $data['per_page_options'] = $this->per_page_options;
    $data['view_module'] = 'items/categories';
    $data['view_file'] = 'manage';
    $this->template('admin', $data);
}

function __destruct() {
    $this->parent_module = '';
    $this->child_module = '';
}
}

Thank you for taking a look at it. If I have done something wrong I apologize, I did take the time and watch https://trongate.io/docs/information/complete-video-tutorial video before posting. It says that parent::__construct() is suppose to resolve this exact issue, and I had it there the entire time, I do not know if the new update broke this, or if I am missing something.

DaFa66 commented 1 year ago

This issue probably needs to be moved to the Help_bar with more information so we can help you better.

Soliaonline commented 1 year ago
  1. Blank
  2. From scratch.
DaFa66 commented 1 year ago

I meant the actual URL in the browser eg. http://localhost/app/items-categories/1

Regardless, I think I can see your problem - in the manage() method $all_rows = $this->model->get('id'); You have to help the framework with a table name because you are in a sub-module, try: $all_rows = $this->model->get('id', 'categories');

I have also spotted a minor framework fix in Trongate.php protected ?string $module_name = ''; This will fix an error when trying to open a normal view from a sub-module, yours will be OK as you are opening a view from a template.

trongate commented 1 year ago

Is this resolved?

DaFa66 commented 1 year ago

I reckon it is - but wait a bit for @Soliaonline to respond...

Soliaonline commented 1 year ago

I feel like in the video it did not do $this->model->get('id', 'categories'), I could be wrong and that's fine. If the fix is to tell trongate where you are, that's fine too. Maybe in the future, if blank check for parent/child module

Soliaonline commented 1 year ago

My final question, is how do I get the API explorer to work then?

https://192.168.0.175/api/explorer/categories => 2 Errors

Warning: foreach() argument must be of type array|object, null given in C:\xampp\webdav\soliaonline\engine\views\api_explorer.php on line 43

Warning: file_get_contents(C:/xampp/webdav/soliaonline/modules/categories/assets/api.json): Failed to open stream: No such file or directory in C:\xampp\webdav\soliaonline\engine\Api.php on line 72

https://192.168.0.175/api/explorer/items-categories => No table

The table is currently blank, so if that is correct, then that needs to be caught with an if statement as well.

PS: can we please get an icon list in the documentation? I know it's basically FA 4, but just want to know what I can and cannot use without opening the trongate app and faking a new creation.

trongate commented 1 year ago

Life: The basics:

1). Assume that the universe owes you nothing.

2). When somebody helps you to solve a problem, THANK THEM.

3). After you've received help, try to make the other person's life BETTER for having interacted with you.

Contemplate this on the Tree of Woe.

Soliaonline commented 1 year ago

I am afraid I do not understand. Do I not have a valid sub module issue? The API isn't working, is it not suppose to if it is a sub module?

Soliaonline commented 1 year ago

@trongate If you would please let me know, I would appreciate it.